# Multiple submits with remote forms

**URL:** <https://www.ruby-forum.com/t/multiple-submits-with-remote-forms/117768>\
**Category:** Rails\
**Created:** [October 20, 2007, 12:47am UTC](https://www.ruby-forum.com/t/multiple-submits-with-remote-forms/117768 "2007-10-20T00:47:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4da419/32.png) [@William\_P](https://www.ruby-forum.com/u/William_P)\
**Post date:** [October 20, 2007, 12:47am UTC](https://www.ruby-forum.com/t/multiple-submits-with-remote-forms/117768/1 "2007-10-20T00:47:13Z")

</div>

I’m sure many of you have run across this one. Using ajax forms in rails  
with multiple submits always sends the value of the first defined submit  
tag rather than the one that is clicked. This is actually against rfc  
and I have read the open trac ticket and they are just trying to figure  
out the best way to solve it since the problem is actually with the  
serialization in prototype. Anyway, I use this little trick to get past  
it and it works well so I thought I would share.

Add a hidden field to the form and a simple onclick action to the submit  
buttons:

\<% form\_remote\_tag :url =\> {:action =\> ‘dispatch\_to\_wanted\_method’} do  
-%\>  
\<%= hidden\_field\_tag :commit\_choice %\>  
… (rest of form)  
\<%= submit\_tag ‘Choice 1’, :onclick =\>  
“$(‘commit\_choice’).value=this.value” %\>  
\<%= submit\_tag ‘Choice 2’, :onclick =\>  
“$(‘commit\_choice’).value=this.value” %\>  
\<% end -%\>

Then, use an if or case statement in your action to look at the value of  
params[:commit\_choice] instead of the actual commit buttons.

Hope this helps save someone some time.

-Bill

–  
Sincerely,

William P.
