http://www.perlmonks.org?node_id=252716


in reply to WWW::Mechanize and checkboxes

You need to specify (uggghh!) the optional $number argument in the field() method:

   The optional "$number" parameter is used to distinguish
   between two fields with the same name.  The fields are
   numbered from 1.
Here is some code to test with. First, the CGI script:
use strict; use warnings; use CGI qw(:standard); print header, start_form, 'Enter something: ', textfield('text1'), checkbox_group( -name => 'checkbox1', -values => [qw(foo bar baz qux)], ), submit('go'), end_form, ; if (param('go')) { print pre(map "$_: @{[param($_)]} \n", param); }
And the Bot to query it with:
use strict; use warnings; use WWW::Mechanize; my $agent = WWW::Mechanize->new(); $agent->get('http://localhost/cgi-bin/foo.cgi'); $agent->form(1); $agent->field(qw(text1 HELO)); $agent->field(qw(checkbox1 foo 1)); $agent->field(qw(checkbox1 baz 3)); $agent->click('go'); print ($agent->{content} =~ /<pre>(.*)<\/pre>/s);
Hope this helps. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)