Submitting forms with Zinc

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Submitting forms with Zinc

Sean P. DeNigris
Administrator
Can Zinc do this easily (e.g. automatically handle hidden fields)? If not, is it planned? Where can I find an example?

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Submitting forms with Zinc

Sven Van Caekenberghe

On 02 Dec 2011, at 22:05, Sean P. DeNigris wrote:

> Can Zinc do this easily (e.g. automatically handle hidden fields)? If not, is
> it planned? Where can I find an example?

Sure, have a look at ZnClientTests>>#testPostForm (and possibly #testPostMultipart).
The API you are looking for is in ZnClient>>#formAt:put: (or #formAdd:) and friends.
This would be an example:

ZnClient new
        url: 'http://myserver.com/login';
        formAt: 'username' put: 'john';
        formAdd: 'password' -> 'secret';
        post.

HTH,

Sven


Reply | Threaded
Open this post in threaded view
|

Re: Submitting forms with Zinc

Sean P. DeNigris
Administrator
Sven Van Caekenberghe wrote
The API you are looking for is in ZnClient>>#formAt:put: (or #formAdd:) and friends.
I tried this with my wordpress site:
ZnNeoClient new
        url: 'http://seandenigris.com/blog/wp-login.php';
        formAt: 'log' put: username;
        formAdd: 'pwd' -> password;
        post.
which failed (I also tried the form element id's instead of names).

The following worked via Ruby's Mechanize:
        a = Mechanize.new { |agent|
                agent.user_agent_alias = 'Mac Safari'
        }
        page = a.get('http://seandenigris.com/blog/wp-login.php')
        form = page.form_with(:name => 'loginform')
        form.log = username
        form.pwd = password
        results = form.submit
        results.body
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Submitting forms with Zinc

Sven Van Caekenberghe
Sean,

It is hard for me to read the Ruby code, but I seems as if they first get the page/form, modify it and then submit it. It is probably important to either do the same, or at least supply all needed fields (there are some hidden ones, look at the HTML source).

Maybe you could try this:

ZnClient new
       url: 'http://seandenigris.com/blog/wp-login.php';
       formAt: 'log' put: 'sean';
       formAt: 'pwd' put: 'password';
       formAt: 'redirect_to' put: 'http://seandenigris.com/blog/wp-admin/';
       formAt: 'testcookie' put: '1';
       post.

In any case, I get an unknown user error back, so the submit basically worked. Now you have to find out what you have to supply as form elements. Let me know how it goes.

Sven

On 04 Dec 2011, at 20:26, Sean P. DeNigris wrote:

>
> Sven Van Caekenberghe wrote
>>
>> The API you are looking for is in ZnClient>>#formAt:put: (or #formAdd:)
>> and friends.
>>
>
> I tried this with my wordpress site:
> ZnNeoClient new
>        url: 'http://seandenigris.com/blog/wp-login.php';
>        formAt: 'log' put: username;
>        formAdd: 'pwd' -> password;
>        post.
> which failed (I also tried the form element id's instead of names).
>
> The following worked via Ruby's Mechanize:
> a = Mechanize.new { |agent|
> agent.user_agent_alias = 'Mac Safari'
> }
> page = a.get('http://seandenigris.com/blog/wp-login.php')
> form = page.form_with(:name => 'loginform')
> form.log = username
> form.pwd = password
> results = form.submit
> results.body
>
> --
> View this message in context: http://forum.world.st/Submitting-forms-with-Zinc-tp4149396p4157792.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>