Can't use www::mechanize with an array form field

I have a website written in PHP/MySQL.

I'm using www::mechanize and www::mechanize::formfiller to test the site.

I declare one of the form fields as an array in PHP like so:

echo "<input type=\"checkbox\" name=\"cat[]\"
value=\"$cat_id\">".VarPrepForDisplay($title)."";

which in turn creates the following HTML code that www::mechanize uses
to test the code.

<input type="checkbox" name="cat[]" value="164">


this makes the cat field an array. the problem is that when I try to
use www::mechanize to submit values to this filed I get the following
error:

Illegal value '211' for field 'cat[]' at /path.pl line 89

Does anyone know how I can submit values to an array based form field?
tim.binary [ Mo, 06 Dezember 2004 12:56 ] [ ID #521831 ]

Re: Can't use www::mechanize with an array form field

Tim <tim.binary [at] gmail.com> writes:

> I have a website written in PHP/MySQL.
>
> I'm using www::mechanize and www::mechanize::formfiller to test the site.
>
> I declare one of the form fields as an array in PHP like so:
>
> echo "<input type=\"checkbox\" name=\"cat[]\"
> value=\"$cat_id\">".VarPrepForDisplay($title)."";
>
> which in turn creates the following HTML code that www::mechanize uses
> to test the code.
>
> <input type="checkbox" name="cat[]" value="164">
>
>
> this makes the cat field an array. the problem is that when I try to
> use www::mechanize to submit values to this filed I get the following
> error:
>
> Illegal value '211' for field 'cat[]' at /path.pl line 89
>
> Does anyone know how I can submit values to an array based form field?

I don't know what it takes in WWW::Mechanize land, but if you have
access to the HTML::Form object you can do this:

$form->param("cat[]", 211, 213);

This will turn on the "211" and "213" check box and all the other
"cat[]" checkboxes off.

Regards,
Gisle
gisle [ Mo, 06 Dezember 2004 15:02 ] [ ID #521832 ]

Re: Can't use www::mechanize with an array form field

On Mon, Dec 06, 2004 at 06:02:14AM -0800, Gisle Aas (gisle [at] ActiveState.com) wrote:
> > Illegal value '211' for field 'cat[]' at /path.pl line 89

Is there actually a cat[] field that has a value of 211? Or are you
trying to fudge an existing field to have a value that it didn't
originally?

xoa

--
Andy Lester => andy [at] petdance.com => www.petdance.com => AIM:petdance
Andy [ Mo, 06 Dezember 2004 16:11 ] [ ID #521835 ]

Re: Can't use www::mechanize with an array form field

>
> Is there actually a cat[] field that has a value of 211? Or are you
> trying to fudge an existing field to have a value that it didn't
> originally?
>

No the value '211' is valid. When I switch the form code back to a
single value - for example without declaring the field as an array as
follows <input type="checkbox" name="cat" value="211"> then my
www::mechanize code works fine. So I know it's because of the array
field declaration.

Thanks for the HTML::Form suggestion - I'll try that.
tim.binary [ Do, 16 Dezember 2004 03:51 ] [ ID #539346 ]
Perl » perl.libwww » Can't use www::mechanize with an array form field

Vorheriges Thema: URI doesn't accept a semi-colon as query parameter separator
Nächstes Thema: How can I "PUT" a large file?