How to post when Java Script modifies the form?

How to post when Java Script modifies the form?

am 06.12.2004 18:35:48 von peter.stevens

Hi everyone,

I am trying to sign in to a site. The form consists of a username and
password field. No problem. But the action attribute of the Form is set
to nil (""). So mech->submit invokes the wrong url.

Looking at the form, I find the routine below to validate the password
and determine where the form should be POSTed to. I can figure out what
the action URL should be. But I do tell Mechanize where it should post to?

Thanks in advance

Peter

function validatePwd(form) {
hostName = pick some arbitrary host name ;
if (document.login.PASSWORD.value.length < minLength) {
...
} else {
document.login.action="https://" + hostName + "/some-login-script";
document.login.submit();

}

}

Re: How to post when Java Script modifies the form?

am 06.12.2004 20:14:16 von toddrw69

"Peter Stevens" wrote in message
news:41B49874.9030409@ch-open.ch...
> Hi everyone,
>
> I am trying to sign in to a site. The form consists of a username and
> password field. No problem. But the action attribute of the Form is set
> to nil (""). So mech->submit invokes the wrong url.
>
> Looking at the form, I find the routine below to validate the password
> and determine where the form should be POSTed to. I can figure out what
> the action URL should be. But I do tell Mechanize where it should post to?
>
> Thanks in advance
>
> Peter
>

Call the action method of the form object and pass in the desired URL:

$agent->form_name( $fName )->action( $action );
# -or-
$agent->current_form->action( $action );

This will set the forms action to the desired URL.

Todd W.

Re: How to post when Java Script modifies the form?

am 07.12.2004 05:18:16 von Andy

On Mon, Dec 06, 2004 at 06:35:48PM +0100, Peter Stevens (peter.stevens@ch-open.ch) wrote:
> Looking at the form, I find the routine below to validate the password
> and determine where the form should be POSTed to. I can figure out what
> the action URL should be. But I do tell Mechanize where it should post to?

Whatever answer you get, please let me know what you find, so I can put
it in the FAQ, but it's a very F-ly AQ.

xoxo,
Andy

--
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance

Re: How to post when Java Script modifies the form?

am 07.12.2004 10:57:31 von peter.stevens

--------------000709000404020404030307
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Sorry - thought I replied to all. Why doesn't reply to direct traffic
back to the list?

In any case, Todd W wrote:

> Call the action method of the form object and pass in the desired URL:
>
> $agent->form_name( $fName )->action( $action );
> # -or-
> $agent->current_form->action( $action );
>
> This will set the forms action to the desired URL.
>
>
This works perfectly! Thanks.

Peter

Andy Lester wrote:

>On Mon, Dec 06, 2004 at 06:35:48PM +0100, Peter Stevens (peter.stevens@ch-open.ch) wrote:
>
>
>>Looking at the form, I find the routine below to validate the password
>>and determine where the form should be POSTed to. I can figure out what
>>the action URL should be. But I do tell Mechanize where it should post to?
>>
>>
>
>Whatever answer you get, please let me know what you find, so I can put
>it in the FAQ, but it's a very F-ly AQ.
>
>xoxo,
>Andy
>
>
>

--------------000709000404020404030307--