# WWW::Mechanize issue when submitting multiple forms

**URL:** <https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740>\
**Category:** Ruby\
**Created:** [April 5, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740 "2007-04-05T18:11:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 5, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740/1 "2007-04-05T18:11:10Z")

</div>

Hi All,

I am using eruby and Mechanize to submit forms on a website. The first  
form  
has a “Accept Agreement” checkbox, when user checks this checkbox and  
submits this form, another form shows up which is the actual input  
form.

When using eruby and Mechanize, I get the first form, check the accept  
checkbox and then get the second form and then populate the fields in  
the  
second form. But when I submit the second form, it shows a page  
saying “You  
did not accept the agreement on first form”. So basically the Accept  
on  
first form is not getting passed while submitting the second form.

here is what I am doing:

agent = WWW::Mechanize.new  
page = agent.get(“[http://www.abc.com](http://www.abc.com)”)  
form = page.forms[1] // get first form  
form.checkboxes.name(‘accept’).check // accept agreement  
page = agent.submit(form) // submit first form  
nextform = page.forms[1] //get next form  
nextform.first\_name = “myname” // populate second form  
nextform.last\_name = “mylastname”  
page = agent.submit(nextform) // submit second form  
puts page.body

Does anyone know how can I get this to work ?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 5, 2007, 8:55pm UTC](https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740/2 "2007-04-05T20:55:28Z")

</div>

On Fri, Apr 06, 2007 at 01:10:04AM +0900, removed\_email\_address@domain.invalid wrote:

> the  
> second form. But when I submit the second form, it shows a page  
> saying “You  
> did not accept the agreement on first form”. So basically the Accept  
> on  
> first form is not getting passed while submitting the second form.
> 
> here is what I am doing:
> 
> agent = WWW::Mechanize.new  
> page = agent.get(“[http://www.abc.com](http://www.abc.com)”)

Is this actually the url you are hitting? I tried it and there is only  
one form on that page.

> form = page.forms[1] // get first form

page.forms[1] is nil for me…

> form.checkboxes.name(‘accept’).check // accept agreement  
> page = agent.submit(form) // submit first form  
> nextform = page.forms[1] //get next form  
> nextform.first\_name = “myname” // populate second form  
> nextform.last\_name = “mylastname”  
> page = agent.submit(nextform) // submit second form  
> puts page.body
> 
> Does anyone know how can I get this to work ?

Can you send an example script with the correct urls in it? If not, try  
installing LiveHTTPHeaders for Firefox, and making sure that firefox  
submits the same thing that mechanize does.

Also, don’t forget to join the mechanize mailing list!

[http://rubyforge.org/mailman/listinfo/mechanize-users](http://rubyforge.org/mailman/listinfo/mechanize-users)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 7, 2007, 10:31am UTC](https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740/3 "2007-04-07T10:31:10Z")

</div>

Hi Aaron,

Thanks a lot for your help !!!

LiveHTTPHeaders was a great help and Mechanize is great library !!!

My issue is resolved.

Thanks,  
Prasanna

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 6, 2007, 11:30am UTC](https://www.ruby-forum.com/t/www-mechanize-issue-when-submitting-multiple-forms/102740/4 "2007-04-06T11:30:57Z")

</div>

Hi Aaron,

Thanks for the information. I installed LiveHTTPHeaders and I think  
Mechanize is sending the same data as Firefox.

I am actually trying to access this URL through Mechanize:

[http://postmaster.info.aol.com/tools/whitelist\_guides.html](http://postmaster.info.aol.com/tools/whitelist_guides.html)

this has the Accept checbox and the next form is the actual input  
form.

Thanks a lot for your help,  
Prasanna
