# Why no multiple submit?

**URL:** <https://www.ruby-forum.com/t/why-no-multiple-submit/61014>\
**Category:** Rails\
**Created:** [May 19, 2006, 9:25am UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014 "2006-05-19T09:25:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@jose](https://www.ruby-forum.com/u/jose)\
**Post date:** [May 19, 2006, 9:25am UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014/1 "2006-05-19T09:25:58Z")

</div>

is it by design? is it standard? how do you give users multiple  
actions on a form?

---

<div class="post-metadata">

**Author:** ![jose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@jose](https://www.ruby-forum.com/u/jose)\
**Post date:** [May 19, 2006, 10:00am UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014/2 "2006-05-19T10:00:56Z")

</div>

You can, just use the variable called params[:commit] in the controller

View:

\<%= form\_tag( :action =\> “multiple\_submit” ) %\>  
\<%= submit\_tag( “Click A”) %\>  
\<%= submit\_tag( “Click B”) %\>  
\<%= end\_form\_tag() %\>

Controller:

def multiple\_submit  
if params[:commit] == “Click A”  
render :text =\> “Clicked on A”  
else  
render :text =\> “Clicked on B”  
end  
end

---

<div class="post-metadata">

**Author:** ![jose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@jose](https://www.ruby-forum.com/u/jose)\
**Post date:** [May 19, 2006, 10:13am UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014/3 "2006-05-19T10:13:56Z")

</div>

If you want to use image as submit tag you need to do it this way:

\<%= image\_submit\_tag("/images/a.gif", { :name =\> “commit”, :value =\> “A”  
} ) %\>  
\<%= image\_submit\_tag("/images/b.gif", { :name =\> “commit”, :value =\> “B”  
} ) %\>

However, this doesn’t work in MS Explorer. Explorer doesnt return the  
variable commit as a parameter but only the 2 variable commit.x and  
commit.y that give you the coordinate of the mouse when the user  
clicked on the picture, this is useless because you still can tell if  
the user clicked on A or B.

You need to do it this way if you want this to work with any browser:

View:

\<%= form\_tag( :action =\> “multiple\_image\_submit” ) %\>  
\<%= image\_submit\_tag("/images/a.gif", { :name =\> “A” } ) %\>  
\<%= image\_submit\_tag("/images/b.gif", { :name =\> “B” } ) %\>  
\<%= end\_form\_tag() %\>

Controller:

def multiple\_image\_submit  
if params[‘A.x’] == “Click A”  
render :text =\> “Clicked on A”  
else  
render :text =\> “Clicked on B”  
end  
end

---

<div class="post-metadata">

**Author:** ![jose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@jose](https://www.ruby-forum.com/u/jose)\
**Post date:** [May 19, 2006, 10:17am UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014/4 "2006-05-19T10:17:11Z")

</div>

Sorry should read:

“if params[‘A.x’]” instead of “if params[‘A.x’] == “Click A””

You just need to test if the variable is defined.

---

<div class="post-metadata">

**Author:** ![jose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@jose](https://www.ruby-forum.com/u/jose)\
**Post date:** [August 13, 2009, 3:07pm UTC](https://www.ruby-forum.com/t/why-no-multiple-submit/61014/5 "2009-08-13T15:07:23Z")

</div>

Thanks for the tip. However, for both IE8 and Firefox 3.0.13, it’s  
params[‘A\_x’]  
Not sure what is for previous IE since my IETester is not installed on  
my test machine.

Gael P. wrote:

> Sorry should read:
> 
> “if params[‘A.x’]” instead of “if params[‘A.x’] == “Click A””
> 
> You just need to test if the variable is defined.
