# Rails - 2 buttoms on a FORM

**URL:** <https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765>\
**Category:** Rails\
**Created:** [November 20, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765 "2008-11-20T21:48:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/54ee81/32.png) [@xads](https://www.ruby-forum.com/u/xads)\
**Post date:** [November 20, 2008, 9:48pm UTC](https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765/1 "2008-11-20T21:48:01Z")

</div>

then, in my FORM there are 2 buttoms :

first to select a file to upload buttom=“Parcourir”  
second to send the complete Form, buttom=“ENVOYER”

“parcourir” is for to select a file to upload

but “ENVOYER” must validate the complete Form :

- file selected presence
- other fields validatation

if evrything is OK, i have to upload the file (and save it)  
and update a Table

how can i do this ?

---

<div class="post-metadata">

**Author:** ![xads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/54ee81/32.png) [@xads](https://www.ruby-forum.com/u/xads)\
**Post date:** [November 21, 2008, 12:35am UTC](https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765/2 "2008-11-21T00:35:03Z")

</div>

You could use javascript to change the target of your form when they  
click  
either button. This can get messy though. Each different form target  
can  
have it’s own validation.

-Jim  
[http://jim-rants.com/coding-blog/](http://jim-rants.com/coding-blog/)

---

<div class="post-metadata">

**Author:** ![xads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/54ee81/32.png) [@xads](https://www.ruby-forum.com/u/xads)\
**Post date:** [November 21, 2008, 7:59am UTC](https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765/3 "2008-11-21T07:59:14Z")

</div>

I guess you want to diferenciate clicks to different submit buttons. I  
did it like this:

\<%= image\_submit\_tag(‘add\_16.png’, :name =\> “action\_categories/new”) %\>

By specifiing name you can differenciate in controller which button was  
selected.

params.each do |e|  
if e[0][0,7] == ‘action\_’  
ctrl, action = e[0][7,100].split(’/’)  
action ||= ‘index’  
break  
end  
end

The example shows which controller/action call when submit button is  
pressed.

by  
TheR

---

<div class="post-metadata">

**Author:** ![xads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/54ee81/32.png) [@xads](https://www.ruby-forum.com/u/xads)\
**Post date:** [November 21, 2008, 12:06pm UTC](https://www.ruby-forum.com/t/rails-2-buttoms-on-a-form/153765/4 "2008-11-21T12:06:31Z")

</div>

On 20 Nov 2008, at 20:48, Xd Xd wrote:

> then, in my FORM there are 2 buttoms :
> 
> first to select a file to upload buttom=“Parcourir”  
> second to send the complete Form, buttom=“ENVOYER”
> 
> “parcourir” is for to select a file to upload

Isn’t this button just going to come “for free” was part of the file  
upload tag?

Fred
