Reinstalling a Rails app on a new server. Part of the app can fork in one of two directions based on the button the user selects. This part isn't working, and when I look at the log I see the values that I gave the form, execept for the commit
portion of the params hash. This seems to be why the app isn't working as expected (since there's nothing in params[:commit]
, but I have no idea why commit would not be passed in; the request is definitely a POST request, and all of the other parameters are there.
views:
161answers:
3
A:
I looked into something like this awhile ago, where there is inconsistency in how different browsers would pass in the value of a submit button on a form. I found the only practical solution was to have javascript in the button to set a hidden field, and use that value instead.
Here is some of my code to differentiate between a save and exit, which goes one way, and save and continue which go another:
<%= hidden_field_tag 'step_commit', '' %>
<span style="float:left;">
<%=submit_tag 'Cancel', :name=>'cancel', :onclick=>"javascript:location.href='/';return false;" %>
<%=submit_tag 'Save and Exit', :name=>'exit', :onclick=>"javascript:$('step_commit').value='exit';" %>
</span>
<span style="float:right;">
<%=submit_tag 'Save and Continue', :name=>'continue', :onclick=>"javascript:$('step_commit').value='continue';" %>
</span>
Andrew Kuklewicz
2010-01-04 16:28:39
The weird thing is it was working fine on the old server, but we just moved it over now and it stopped.
Wayne M
2010-01-04 16:29:38
A:
Check that your submit input is named commit or it's label will not be sent.
The resulting html should be:
<input type="submit" name="commit" label="...>
makevoid
2010-01-04 16:31:24
A:
Had a simular problem with a disable-button-on-submit feature. We solved it by adding a hidden input field with the same name and value before submitting the form.
function disableButtonAndSubmit()
{
var input = $("<input type='hidden' />").attr("name", $(this)[0].name).attr("value", $(this)[0].value);
$(this).closest('form').append(input);
$(this).attr('disabled', 'disabled').html('Loading…');
$(this).closest('form').submit();
}
$('#somewhere button').click(disableButtonAndSubmit);
Joakim Kolsjö
2010-04-30 07:52:07