What you mean terribly written HTML? I's a valid XHTML tag. I expected you put the code with WWW::Mechanize and pointed out which part didn't work as you expect. But OK, supposed we have a HTML file (form.html) with the following simplified content:
<form>
<input type="checkbox" name="passenger" value="somevalue" />
<input type="submit" name=".submit" value="OK">
</form>
Update: (21-06-2007) Oops, fixed the submit field.
The following example (tick.pl) demonstrates the checkbox ticking.
use strict;
use warnings;
use WWW::Mechanize;
# set some dummy vars
my $target_field = 'passenger';
my $target_value = 'somevalue';
# get the URL and check
my $url = shift or die "Need URL, pal!\n";
my $mech = WWW::Mechanize->new;
$mech->get($url);
$mech->success or die $mech->response->status_line, "\n";
# select the form
$mech->form_number(1);
# check original value
my $set_value = $mech->value($target_field);
$set_value = 'undef' unless defined $set_value;
print "[1] value for $target_field: ($set_value)\n";
# tick the checkbox
$mech->tick($target_field, $target_value);
$set_value = $mech->value($target_field);
$set_value = 'undef' unless defined $set_value;
print "[2] value for $target_field: ($set_value)\n";
And supposed that the form URL is http://localhost/form.html, the program produces the following when run:
$ perl tick.pl http://localhost/form.html
[1] value for passenger: (undef)
[2] value for passenger: (somevalue)
HTH,
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|