# How to make two forms on the same page?

**URL:** <https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607>\
**Category:** Rails\
**Created:** [March 9, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607 "2006-03-09T21:15:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [March 9, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/1 "2006-03-09T21:15:25Z")

</div>

I can get the forms to be displayed, but i want to have only one  
“create” button. i’ve tried everything i can think of…

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [March 9, 2006, 9:42pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/2 "2006-03-09T21:42:37Z")

</div>

On 3/9/06, jon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can get the forms to be displayed, but i want to have only one “create”  
> button. i’ve tried everything i can think of…

_If_ I understand you, you want to have something like…

[form1]  
[field1]  
[field2]  
[end\_form1]  
[form2]  
[field3]  
[submit]  
[end\_form2]

…and have the submit button submit both form1 and form2?

That’s not something regulation HTML is capable of\*. Is there a reason  
you  
can’t you just combine the forms?

- You /could/, _technically_, do this in JavaScript with onsubmit(), but  
it’s error-prone and - at best - only works with JavaScript-enabled  
browsers.

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/3 "2006-04-05T17:33:20Z")

</div>

How do you have 2 forms on the same page with 2 diiferent submit tags?

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/4 "2006-04-05T17:37:53Z")

</div>

Well they cross paths when i render a partial but when they are  
currently on the same page they have the following code:

**Leave a Reply**  
\<%= form\_tag :action =\> “comment”, :id =\> @post %\>  
\<%= render :partial =\> ‘commentform’ %\>

\<%= submit\_tag "Comment!" %\>

and

\<%= form\_tag :action =\> ‘search’ %\>

\<%= text\_field\_tag 'search' , params[:search], "size" =\>"20" %\> \<%= submit\_tag 'Search' %\>

\<%= end\_form\_tag %\>

The 1st form Leave a reply gets called regardless of which submit button  
i click.

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:34pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/5 "2006-04-05T17:34:38Z")

</div>

John B. wrote:

> How do you have 2 forms on the same page with 2 diiferent submit tags?

Can you post the rhtml you’re currently trying ?

Alan

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/6 "2006-04-05T17:38:58Z")

</div>

John B. wrote:

> Well they cross paths when i render a partial but when they are  
> currently on the same page they have the following code:
> 
> **Leave a Reply**  
> \<%= form\_tag :action =\> “comment”, :id =\> @post %\>  
> \<%= render :partial =\> ‘commentform’ %\>
> 
> \<%= submit\_tag "Comment!" %\>
> 
> and
> 
> \<%= form\_tag :action =\> ‘search’ %\>
> 
> \<%= text\_field\_tag 'search' , params[:search], "size" =\>"20" %\> \<%= submit\_tag 'Search' %\>
> 
> \<%= end\_form\_tag %\>
> 
> The 1st form Leave a reply gets called regardless of which submit button  
> i click.

There’s no end\_form\_tag after the first form ?

Alan

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/7 "2006-04-05T17:45:39Z")

</div>

problem solved!

I’m having 1 of those days, time to finish up for the day i think

Thanks

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 5, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/how-to-make-two-forms-on-the-same-page/54607/8 "2006-04-05T17:41:52Z")

</div>

\<…\>

> \<%= submit\_tag ‘Search’ %\>
> 
>   
> \<%= end\_form\_tag %\>
> 
> The 1st form Leave a reply gets called regardless of which submit button  
> i click.

Where’s your end\_form\_tag for the first form?

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)
