Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Using Mechanize With Odd Query String

by varanasi (Scribe)
on Mar 03, 2012 at 17:57 UTC ( #957699=perlquestion: print w/replies, xml ) Need Help??

varanasi has asked for the wisdom of the Perl Monks concerning the following question:

Using Mechanize, I am trying to pass a name/value pair to a form that looks like this:

<form action="action.cgi?use-a" method="post" > <input type="submit" value="entry one" >&nbsp;for&nbsp; <select name="target"> <option value="">User <option value='195'>Affiliate </select> </form>

Other variants of action.cgi work fine for me, e.g. action.cgi?use-f, but those variants don't require a name value/pair to work. I simply do a $browser->get() on them. If I simply get action.cgi?use-a, the cgi script acts as if I had selected the User option, since it received no name/value pair.

I have tried many ways of structuring the url directly but without any success. I have also tried using LWP's post method, without success, like this:

$browser->post("$BASEURL?use-a", 'target' => '195');

I am stumped (and probably stupid.) Would you be kind enough to help?

Replies are listed 'Best First'.
Re: Using Mechanize With Odd Query String
by repellent (Priest) on Mar 03, 2012 at 21:12 UTC
    Your form key/value pairs need to be specified as Content:
    $browser->post("$BASEURL?use-a", { 'target' => '195' } ); # now a hash +ref

    The documentation for ->post mentions $field_name which may be confused as being a form key name. The $field_name => $value pairs actually get pushed onto the Header instead of the Content.
      Thank you. I did not understand the documentation even when I re-read it. Thank you for explaining it succinctly.
Re: Using Mechanize With Odd Query String
by Gangabass (Vicar) on Mar 05, 2012 at 09:33 UTC
    Just load this form's page with $mech->get(...) and do:
    $mech->submit_form( form_number => 1, fields => { target => "Affiliate", }, );
    But you need to check form_number param by yourself.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://957699]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2023-10-02 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?