Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re-submit HTML form including inputs

by hgolden (Pilgrim)
on Sep 11, 2006 at 13:37 UTC ( [id://572347]=note: print w/replies, xml ) Need Help??


in reply to Re-submit HTML form including inputs

So I've never used HTML::Form, but this question has gone unanswered for a while, so I'll take a crack at it. My apologies if I'm no help.

When you say that you're losing the inputs, do you mean that LWP is submitting a blank form, or that it submits the form, but you no longer have the inputs, which you may want to process locally (e.g. to label the response you get from the server)?

If it's that you want the form values to persist locally, it's probably easiest to set up a hash which is keyed by the value name.

The more likely case is that it's submitting a blank form. Now, I usually do this stuff by capturing a sample post and editing the header directly. In that case, I would use the post method as you do. Is it possible that you should be using one of LWP's three request methods? Check out http://kobesearch.cpan.org/htdocs/libwww-perl/LWP/UserAgent.html and try those out. If that still doesn't work, why don't you private message me, and I'd be happy to take a look at your full code. I have a not-so-busy day at work today, and I bet we can get this working.

Hays

  • Comment on Re: Re-submit HTML form including inputs

Replies are listed 'Best First'.
Re^2: Re-submit HTML form including inputs
by muzza1962 (Initiate) on Sep 12, 2006 at 02:35 UTC
    Hi Hays, Thanks for the response. I'll clarify my problem a bit. The lines below get a user edit form including the current values in the input fields eg. username, password etc. I can successfully print all the values using the form->dump function.
    $response = $ua->request(HTTP::Request->new(GET => "$edit_user_url")); my $form = HTML::Form->parse($response); #print $form->dump; # print form values
    I can then get or change any of these values using $form->value("field") or $form->value("field",$newvalue). My problem is that when I do a $form->make_request or $form->click the field values appear not to be submitted. How do I submit the form including all the current values? Murray
      So I think the issue is that when you resubmit the form, you're using post which will try and generate a HTTP::Request object. The problem is that you already have such an object.

      Here's an example from http://www.icewalkers.com/Perl/5.8.0/lib/HTML/Form.html:

      use HTML::Form; $form = HTML::Form->parse($html, $base_uri); $form->value(query => "Perl"); use LWP; LWP::UserAgent->new->request($form->click);
      Both click and make_request return request objects, and you can see that they're using LWP's request to send them.

      I was trying to point you to this in my first post, though I admit that it was pretty unclear. Check out http://kobesearch.cpan.org/htdocs/libwww-perl/LWP/UserAgent.html#ua_gt_request_request.

      See how $ua->request sends a request object? Try that on your $req which is such a request object, and let me know if that doesn't work.

      Hays

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2025-05-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.