Submitting a form with two identically named fields using WWW::Mech
am 16.05.2007 22:46:41 von pknewsgroups
Hello!
I was programming some web automation stuff using Mech and found the
following.
Suppose someone not too skillful at designing HTML forms had made a form
with two elements,
a checkbox and a text field, and both assigned the same name 'element_name'.
Now if I call Mech's submit_form() and specify both fields, the Mech
would die with the following error:
"Illegal value 'false' for field 'element_name' at Mechanize.pm line ..."
This error originates in HTML::Form which apparently checks if the form
element's type matches the element's value.
It doesn't seem right that Mech will die just because of someone
specifying two fields with the same name.
For example, Mech could figure out which value belongs to which field
and then submit both of them in order they appear in the form.
(This is what FireFox does if a form has two fields with the same name,
and then it's up to server side to decide which value to use)
Thanks,
P.Krumins
Re: Submitting a form with two identically named fields using WWW::Mech
am 16.05.2007 22:53:54 von Andy
On May 16, 2007, at 3:46 PM, Peteris Krumins [Newsgroups] wrote:
> Now if I call Mech's submit_form() and specify both fields, the
> Mech would die with the following error:
> "Illegal value 'false' for field 'element_name' at Mechanize.pm
> line ..."
Can you give a specific code snippet that fails? It would let me
make a test out of it, and make everything clear to all reading
(including me).
--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
Re: Submitting a form with two identically named fields using WWW::Mech
am 16.05.2007 23:12:47 von pknewsgroups
Andy Lester wrote:
> On May 16, 2007, at 3:46 PM, Peteris Krumins [Newsgroups] wrote:
>
>> Now if I call Mech's submit_form() and specify both fields, the Mech
>> would die with the following error:
>> "Illegal value 'false' for field 'element_name' at Mechanize.pm line
>> ..."
>
>
> Can you give a specific code snippet that fails? It would let me
> make a test out of it, and make everything clear to all reading
> (including me).
I am writing a script which will automatize form submission on some
websites.
There is a video sharing website www.bolt.com which has a registration
form with two elements named 'signupMe' - a text field and checkbox.
The text field has default value "false" and the checkbox has a default
value "on".
Here it is an example which will cause Mech to die:
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new;
$mech->get('http://www.bolt.com/registration/index.bt');
$mech->submit_form(
with_fields => {
signupMe => "on",
signupMe => "false",
}
);
I'd like Mech not to die and rather figure out which value belongs to
which type of field (text field or checkbox) and just
submit both of them in order they appear in the form as FireFox does.
P.Krumins