Re: how to send form action?

Peter Scott <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Organization Pacific Systems Design Technologies
Message-ID <[email protected]>
On Mon, 11 Sep 2006 12:58:03 -0300, Toshiro (mailing lists) wrote:
>> > Please have a look at the html form below (I'm only showing the relevant parts);
>> >
>> > I'm trying to get the data from the form with this:
>> >
>> >   $mech->submit_form(
>> >      fields => {
>> >         txtRateSheetID => "20000",
>> >         txtAction => "VIEW",
>> >         txtLevelTypeID => "1",
>> >         txtCategoryTypeID => "9",
>> >
>> > But I'm failing to get the page I need; I guess it's because I haven't
>> > set the action property (action=strPage , according to the
>> > Javascript).
>> >
>> > The question is: how do I define the action to be performed?
>>
>> Get the form object.  perldoc HTML::Form.  Look for action() method.
>> Figure out what the JavaScript would set the action to.  Set it to that.
>>
> I've been trying to do what you suggested, but I don't know how to use
> Mech and HTML::Form together,
> For example, the html page that has the form is the result of a previous
> form that I get with Mechanize using this:
> 
>  my $response = $mech->submit_form();
> 
> then I set the form value and form data with these:
> 
>  my $form = HTML::Form->parse($response);
>  $form->action("strPage");

Odd looking URL there, but not impossible.

>  $form->value("txtRateSheetID", "20000");
>  $form->value("txtAction", "VIEW");
>  $form->value("txtLevelTypeID", "1");
>  $form->value("txtCategoryTypeID", "9");
>  $form->value("txtRateSheetTypeID", "1");
> 
> now, how can I retrieve the contents of this form and save it using
> $mech->save_contents ?

my $form = $mech->form_number(1);
$mech->set_fields(txtRateSheetID => 20000, ...);
$form->action('strPage');
$mech->submit;
$mech->save_content($filename);

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.