Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

How do I uncheck a checkbox with WWW::Mech?

by hesco (Deacon)
on Apr 03, 2011 at 01:53 UTC ( #897141=perlquestion: print w/replies, xml ) Need Help??
hesco has asked for the wisdom of the Perl Monks concerning the following question:

sub www_mech_deactivate { my $self = shift; my $email = shift; my $uid = $self->get_uid_from_email($email); my $path = $self->{'cfg'}->param("paths.subscription_management_page +"); $path =~ s/UID/$uid/; $self->{'agent'}->get($path); # this works to subscribe person to all lists: $self->{'agent'}->submit_form( form_number => 2, fields => { 'newsletters[65]' => '65', 'newsletters[34]' => '34', 'newsletters[17]' => '17', 'newsletters[71]' => '71', } ); # But all of these attempts fail . . . $self->{'agent'}->untick('newsletters[17]'); $self->{'agent'}->untick('newsletters[65]',''); $self->{'agent'}->untick('newsletters[34]','checked'); $self->{'agent'}->untick('newsletters[71]','71'); $self->{'agent'}->submit_form( form_number => 2 ); return; }
UPDATE:

Thanks Wind, I just tried that, and still I get the following errors:

No checkbox "newsletters[17]" for value "17" in form at /home/hesco/li +b/CMS/Drupal/SimpleNews.pm line 70 No checkbox "newsletters[34]" for value "34" in form at /home/hesco/li +b/CMS/Drupal/SimpleNews.pm line 71 No checkbox "newsletters[71]" for value "71" in form at /home/hesco/li +b/CMS/Drupal/SimpleNews.pm line 72 No checkbox "newsletters[83]" for value "83" in form at /home/hesco/li +b/CMS/Drupal/SimpleNews.pm line 73
And to give some sense of the html I'm interacting with:

<div class="form-item form-option" id="edit-newsletters-34-wrapper"> <label class="option" for="edit-newsletters-34"><input type="check +box" name="newsletters[34]" id="edit-newsletters-34" value="34" chec +ked="checked" class="form-checkbox" /> Guests</label> </div>
Can anyone please offer some additional guidance, please?

-- Hugh

if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

Replies are listed 'Best First'.
Re: How do I uncheck a checkbox with WWW::Mech?
by wind (Priest) on Apr 03, 2011 at 02:53 UTC
    The documentation for WWW::Mechanize says tick and untick accept the following parameters:

    $mech->tick( $name, $value [, $set] )

    $mech->untick( $name, $value )

    I therefore suspect that what you really need to do is the following:

    $self->{'agent'}->untick('newsletters', 17); $self->{'agent'}->untick('newsletters', 65); $self->{'agent'}->untick('newsletters', 34); $self->{'agent'}->untick('newsletters', 71);
    Or more succiently
    $self->{'agent'}->untick('newsletters', $_) for (17, 65, 34, 71);

    However, not knowing the form or the html that you're accessing, I can't say for sure what you're doing incorrectly. Can only go on the way it looks.

Re: How do I uncheck a checkbox with WWW::Mech?
by Anonymous Monk on Apr 03, 2011 at 07:12 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://897141]
Approved by GrandFather
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-07-18 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (388 votes). Check out past polls.

    Notices?