Forum: Ruby on Rails two submit buttons..

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2007-01-08 15:06
I am using two submit buttons within my form without any problem, as
specified (

 BUT  when the user doesn't hit a button and just hit ENTER, I got the
first button submit in my controller which unfortunatly is the Cancel
button in my view...

Yes, if I change the button position (OK first in html..) I get it.. but
I'd like to keep my display as required by the users... Cancel button
must come before OK button....

<div class="submit">
     <%= submit_tag "Cancel", {:name => "submit", :class =>
"inputSubmit" }%>
     <%= submit_tag "OK»", {:name => "submit", :class => "inputSubmit"}

is ther any way to do that ?

thanks a lot fyl
11364e09c2ea04444314e94eead06e98?d=identicon&s=25 Roland Swingler (Guest)
on 2007-01-08 15:19
(Received via mailing list)
Could you not use CSS to position the buttons in another order?

For example, one of:

div.submit div {
  position: relative;

/* you would need to define separate classes for the ok and cancel
buttons */

div.submit div .okButton {
  position: absolute;
  top: 0px;
  left: 0px;

div.submit div .cancelButton {
  position: absolute;
  top: 0px;
  left: 100px; /* or however wide your buttons are */


div.submit div {
  float: right;

I haven't tested either of these, but you should be able to do
something similar to swap the button order.


On Jan 8, 2:06 pm, Kad Kerforn <>
6b7459aca37bf49900de66dc2113e163?d=identicon&s=25 David Schmidt (Guest)
on 2007-01-19 16:30
(Received via mailing list)
Try setting the tab order using tabindex:

<%= image_submit_tag( "buttons/ok.gif",
                                        :border => "0",
                                        :title => 'Submit page',
                                        :id => 'ok_button',
                                        :tabindex => 13) %>

Just make sure that your OK button is earlier in the tabindex order than
the Cancel button.

Here are some references:

0c1d26989fe0a2eea6daf6cdb5c7484b?d=identicon&s=25 Oliver (Guest)
on 2007-02-15 21:55
(Received via mailing list)
On this two submit button subject, have anyone successfully tried the
":name" technique in a form_remote_tag case? In the following example,
params[:preview] and params[:ok] are both present, so can't tell which
button is clicked, any idea how to get around this?

<%= form_remote_tag ..>
  <image_submit_tag("ok.gif", :name=>"ok")%>
  <image_submit_tag("preview.gif", :name=>"preview")%>
<%= end_form_tag %>


A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-15 22:05
(Received via mailing list)
if i remember correctly, the way around this is to have a hidden field
in the form and when you click the submit button, you set the value on
the hidden field to indicate what button was clicked.  you can then
check this hidden field value on the server.
0c1d26989fe0a2eea6daf6cdb5c7484b?d=identicon&s=25 Oliver (Guest)
on 2007-02-15 22:38
(Received via mailing list)
hmm ... not sure why this can work. If I understand it correctly, A
hidden field is part of the submitted form, not associated with the
submit button. <%= hidden_field_tag ... %> will be submitted along
with the rest of the form, but still not sufficient to make a
distinction. Maybe I get you wrong, an example will be good.

thanks for the reply.

A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-16 12:32
(Received via mailing list)
off the top of my head...not tested.  not even sure if you need the
submit() call in the onclicks as it may still get submitted because of
the submit buttons. give it a shot.

<%= form_remote_tag ..., :html => { :id => 'my_form' }  %>
  <%= submit_tag "Delete", :onclick => "$('form_action').value =
'delete';$('my_form').submit()" %>
  <%= submit_tag "Update", :onclick => "$('form_action').value =
'update';$('my_form.submit();" %>
  <%= hidden_field_tag "form_action", "", :id => "form_action" %>
<%= end_form_tag %<
This topic is locked and can not be replied to.