# Quick Submit Button Question

**URL:** <https://www.ruby-forum.com/t/quick-submit-button-question/136331>\
**Category:** Rails\
**Created:** [April 30, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331 "2008-04-30T21:57:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [April 30, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/1 "2008-04-30T21:57:03Z")

</div>

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 M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 12:00am UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/2 "2008-05-01T00:00:18Z")

</div>

check your params–you might find it’s already in there.

On Wed, Apr 30, 2008 at 1:57 PM, Jeff M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 1:13am UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/3 "2008-05-01T01:13:32Z")

</div>

On Apr 30, 2008, at 3:57 PM, Jeff M. wrote:

> \<%= 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 M.

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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 4:34am UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/4 "2008-05-01T04:34:30Z")

</div>

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

Good Luck  
Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 3:46am UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/5 "2008-05-01T03:46:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 1, 2008, 9:41pm UTC](https://www.ruby-forum.com/t/quick-submit-button-question/136331/6 "2008-05-01T21:41:43Z")

</div>

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 M.
