Hello,
Can I pass a variable from a submit button only? I have a form that the
user fills out and I need two different submit buttons - one for 'sync'
and one for 'full push'. I was thinking I could add some sort of param
to the button, but it's not working... is there a way to do this? I have
this:
Unless you gave a :name => nil option to your submit_tag, you can test params[:commit] for the button label (or, I think, supply your own :value => 'sync' or :value => 'full')
I've used this to give both a "Create" and a "Create and Add Child" button to a form that changed where you were redirected on success.
I'm a newbie myself, but suspect that submit_tag can not be made to do
this. To pass arbitrary parameters to your controller from a form you
specify them on the form_for call.
One option that comes to mind is to give the user a drop-down to select
which of the two types of submits they want to do. I don't suppose that
appeals?
Thanks guys, I ended up passing it through Javascript, like the last
suggestion. And yes, it turns out that HTML submit buttons cannot pass
variables themselves, as they just initiate the post.