Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

(jeffa) Re: WWW::Mechanize and checkboxes

by jeffa (Bishop)
on Apr 23, 2003 at 23:43 UTC ( #252716=note: print w/ replies, xml ) Need Help??


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)


Comment on (jeffa) Re: WWW::Mechanize and checkboxes
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://252716]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (16)
As of 2015-07-29 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls