Re: Problems with a Submit Input Requiring a Value

Hal Vaughan <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
Gisle Aas wrote:

> On Tue, Jun 17, 2008 at 6:42 PM, Hal Vaughan <[email protected]> wrote:
>> I've never seen this before so it could be I'm outdated, but I'm reading
>> a
>> page that has two submit buttons in one form.  Here's the code for both
>> of them:
>>
>> <input type="submit" name="caseSearch" value="Search" onclick="return
>>        validateCaseNumber();" class="payBox">
>> <input type="submit" name="paymentCaseSearch" value="Search To Pay"
>>        class="payBox longBox">
>>
>> I've used Wireshark and Firefox to track the POST data that is sent out
>> when
>> POSTing this form back to the server.  When I click on the caseSearch
>> submit button in Firefox, it includes the value pair "caseSearch=Search"
>> in the POST data that goes back to the server.
>>
>> When I use WWW::Mech to submit, that is not sent as POST data.  I've
>> tried to force it by setting the value to Search, but it was already at
>> that value and it's not included.
> 
> I think you need to demonstrate the problem with some runnable sample
> code.  When I test it here it seems to do the right thing:
> 
> #!perl -w
> use strict;
> use HTML::Form;
> 
> my $f = HTML::Form->parse(<<'EOT', "http://example.com");
> <form method="POST">
> 
> <input type="submit" name="caseSearch" value="Search" onclick="return
>        validateCaseNumber();" class="payBox">
> <input type="submit" name="paymentCaseSearch" value="Search To Pay"
>        class="payBox longBox">
> 
> </form>
> EOT
> 
> #$f->dump;
> print $f->click("caseSearch")->as_string;
> __END__
> 
> When I run this program it prints:
> 
> POST http://example.com
> Content-Length: 17
> Content-Type: application/x-www-form-urlencoded
> 
> caseSearch=Search

Hmmmm...  You're just clicking.  I didn't realize I could do that because I
was so caught up in using Mech I think I overlooked dealing with the form
directly, probably because I wanted Mech to have all the info as well.

In the end it occurred to me that on the server side all you get are
name/value pairs and nothing to indicate the type of form input being used,
so after Mech got the page, I grabbed the content, changed that field from
submit to text, replaced the page content with my edited version, and
submitted and it worked fine, since it did POST the setting for the text
field.

Thanks!

Hal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.