Quick Submit Button Question...

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:

<%= 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?

Thanks, - 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

Rob Biedenharn http://agileconsultingllc.com Rob@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 appeals?

<%= 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 : http://railsmanual.org/module/ActionView::Helpers::UrlHelper/button_to/1.1.2

Good Luck Reinhart http://teapoci.blogspot.com

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