Quick Submit Button Question...

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

<%= submit_tag 'push to Exchange', :name => "rad", :id => "0", :onclick
=> "doClick(this)" %>

<%= submit_tag 'force full push', :name => "radtwo", :full => "full",
:onclick => "doClick(this)" %>

I tried to add param[:full], but it doesn't work. Any suggestions?

- Jeff Miller

check your params--you might find it's already in there.

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.


Rob Biedenharn http://agileconsultingllc.com

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

<%= submit_tag 'force full push', :name => "radtwo", :full => "full",
:onclick => "doClick(this)" %>

You should specify params[:full] at function doClick(this). But if you
put 2 submit_tag buttons there, it's nasty way. Another way is :

<%= submit_tag 'push to Exchange', :name => "rad", :id => "0", :onclick
=> "doClick(this)" %>

<%= button_to_function 'force full push', {:name => "radtwo", :full =>
"full"}, :onclick => "doClick(this)" %>

Another way is :
<%= button_to "push to Exchange", {:action=>'go',:name => "rad", :id =>
"0"}, :onclick => "doClick(this)" %>

<%= button_to "force full push", {:action => 'where', :name => "radtwo",
:full => "full"}, :onclick => "doClick(this)" %>

Reference :

Good Luck

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.

Thanks again,
- Jeff Miller