I have a form with the following:
<% form_remote_tag :url => {:action => :wotsit} do %>
<%= submit_tag "Foo" %>
<%= submit_tag "Bah" %>
<% end %>
I would expect that the submitted parameters would reflect which button had been clicked. However, no matter which button I click, the submitted parameters include "commit"=>"Foo"
.
What am I doing wrong?
form_remote_tag generates some Javascript that uses Prototype's Form.serialize method to send the values of your form fields to the server. Form.serialize is always using the first element that has the name "commit", so it's always "Foo".
As a work-around you could add a hidden field & have your submit tags set that field & submit the form:
<%= hidden_field_tag "real_commit", "" %>
<%= button_to_function "Foo", "$('real_commit').value='Foo';$('myform').submit();" %>
<%= button_to_function "Bah", "$('real_commit').value='Bah';$('myform').submit();" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With