Why no multiple submit?

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

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

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

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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs