# How to provide 2 actions to a form?

**URL:** <https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659>\
**Category:** Rails\
**Created:** [March 14, 2006, 11:30am UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659 "2006-03-14T11:30:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 11:30am UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/1 "2006-03-14T11:30:28Z")

</div>

Hi,  
I have a form in rhtml. Now I have 2 buttons indside that form. Clicking  
on the first button action will be ‘create’ & on second button action  
will be ‘delete’. How to do this?  
Thanx  
Prash

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 1:21pm UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/2 "2006-03-14T13:21:49Z")

</div>

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

> I have a form in rhtml. Now I have 2 buttons indside that form. Clicking  
> on the first button action will be ‘create’ & on second button action will  
> be ‘delete’. How to do this?

Probably the easiest way is to give up on the ‘delete’ action being a  
button, and just making it a link. (You could use images or CSS to style  
the  
link and the button very similarly.)

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 1:58pm UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/3 "2006-03-14T13:58:41Z")

</div>

Don’t know much about RoR, but it’s pretty simple actually !

if post-\>b1 =“submit”  
execute-\>action1  
elseif post-\>b2 =“submit”  
execute-\>action2

Josh on Rails wrote:

> On 3/14/06, Prashant T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I have a form in rhtml. Now I have 2 buttons indside that form. Clicking  
> > on the first button action will be ‘create’ & on second button action will  
> > be ‘delete’. How to do this?
> 
> Probably the easiest way is to give up on the ‘delete’ action being a  
> button, and just making it a link. (You could use images or CSS to style  
> the  
> link and the button very similarly.)

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/4 "2006-03-14T14:20:38Z")

</div>

stupid me  
sorry… just tired I guess

if submit = v1  
…  
…  
…

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 2:36pm UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/5 "2006-03-14T14:36:34Z")

</div>

OKAY, just to be a nice guy

template  
\<%= form\_tag(:action =\> “action2”)%\>  
\<%= submit\_tag ‘Edit’, :name =\> ‘\_edit\_button’ %\>  
\<%= submit\_tag ‘Delete’, :name =\> ‘\_delete\_button’ %\>  
\<%= end\_form\_tag %\>

controller  
def action2  
render\_text params[:\_update\_button]  
end

I hope it’s pretty self explainatory !!!

Alex Copot wrote:

> stupid me  
> sorry… just tired I guess
> 
> if submit = v1  
> …  
> …  
> …

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [March 14, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/how-to-provide-2-actions-to-a-form/81659/6 "2006-03-14T14:39:21Z")

</div>

OKAY - I’m an idiot for today

template  
\<%= form\_tag(:action =\> “action2”)%\>  
\<%= submit\_tag ‘Edit’, :name =\> ‘\_button’ %\>  
\<%= submit\_tag ‘Delete’, :name =\> ‘\_button’ %\>  
\<%= end\_form\_tag %\>

controller  
def action2  
render\_text params[:\_button]  
end
