Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I'm using LWP::UserAgent and HTTP::Request::Common to automate filling out a form. This form has multiple submit buttons, like in the code below.
<input name="screen" type=submit value="Retrieve data to screen"> <input name="email" type=submit value="Retrieve data by email"> <input name="ftp" type=submit value="Retrieve data by ftp">
I am trying to submit using the 1st option, "Retrieve to screen". My current code:
my $response = POST $form_url, [ some => "options", screen => "Retrieve data to screen", ];
Is submitting the data to the url ok and generating a response. However the response claims that I have not chosen where the data is to displayed (eg. one of the buttons). I think this might be happening because I am not submitting values for 'ftp' or 'email' values. I have tried submitting "", but I'm not having much luck. What is the correct way to handle multiple submit options? Is there something obvious I have missed? Thanks!

Replies are listed 'Best First'.
Re: LWP Multiple Submit Buttons
by Corion (Patriarch) on Jul 16, 2004 at 11:30 UTC

    Here's my checklist of things to check when automating web pages:

    1. Does the page work with your browser?
    2. What data is your browser sending?
    3. What data is your program sending?
    4. Where do they differ?
    5. How can you make them both send the same data?

    In your case, I recommend starting over by using WWW::Mechanize, which has a click() method that faithfully simulates what many browsers send when you click on a form submit button.

      Hi. Thanks for that suggestion I'll have a go with Mechanize. Also is there a good way to see what my browser is sending?

        This really depends on what browser you are using. For Mozilla and Fire$ANIMAL, there is liveheaders, which displays the sent headers in a separate window. If you are using another browser, you might want a proxy which dumps all traffic going through it. Such a proxy could be written with HTTP::Proxy for example, but other solutions are also possible, by simply sniffing all traffic with ethereal or Net::PCap.

        Even if you are using WWW::Mechanize, it's not a panacea - there will come a time when you really need to see what the differences are to make WWW::Mechanize mimic a specific browser in the closest possible way.