# Question about Form

**URL:** <https://www.ruby-forum.com/t/question-about-form/107387>\
**Category:** Rails\
**Created:** [June 21, 2007, 4:31am UTC](https://www.ruby-forum.com/t/question-about-form/107387 "2007-06-21T04:31:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![huang\_zhimin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/54ee81/32.png) [@huang\_zhimin](https://www.ruby-forum.com/u/huang_zhimin)\
**Post date:** [June 21, 2007, 4:31am UTC](https://www.ruby-forum.com/t/question-about-form/107387/1 "2007-06-21T04:31:11Z")

</div>

I have a case that a form has two submit button,  
one is edit button that only change the current div that can use  
form\_remote\_tag,  
the other is delete button that should refresh the whole page that can  
use  
form\_tag.

But I what use edit and delete button both in a form, how can I do that?

–

> **[CodeLineStatistics](https://sourceforge.net/projects/mycodeline/)**
>
> Download CodeLineStatistics for free. The code line statistics takes files and directories from GUI, counts the total files, total sizes of files, total lines, lines of codes, lines of comments and lines of blanks in the files, displays the results...

---

<div class="post-metadata">

**Author:** ![huang\_zhimin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/54ee81/32.png) [@huang\_zhimin](https://www.ruby-forum.com/u/huang_zhimin)\
**Post date:** [June 21, 2007, 5:11am UTC](https://www.ruby-forum.com/t/question-about-form/107387/2 "2007-06-21T05:11:13Z")

</div>

On 6/21/07, huang zhimin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a case that a form has two submit button,  
> one is edit button that only change the current div that can use  
> form\_remote\_tag,  
> the other is delete button that should refresh the whole page that can use  
> form\_tag.
> 
> But I what use edit and delete button both in a form, how can I do that?
> 
> –

I think javascript is the only way I can think of.

One way would be to load the page, and then attach an event listener to  
the  
submit event of the form. Then you detect if it’s an edit click, in  
which  
case make an ajax request and the stop the event with Event.stop( event  
).  
If it’s the delete button do nothing and let the form take it’s natural  
course.

Daniel

---

<div class="post-metadata">

**Author:** ![huang\_zhimin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/54ee81/32.png) [@huang\_zhimin](https://www.ruby-forum.com/u/huang_zhimin)\
**Post date:** [June 21, 2007, 6:14am UTC](https://www.ruby-forum.com/t/question-about-form/107387/3 "2007-06-21T06:14:16Z")

</div>

typically if you’re going to use more than one submit button inside a  
form, then you can check to see which was clicked in two ways:

1. name both buttons the same, and check which value is posted

if params[:btnSubmit] == “submit one”  
… do this …  
else  
… do that …  
end

1. name the buttons differently, and see which posts a value

if params[:btnSave]  
… do this …  
elsif params[:btnCancel]  
… do that …  
end

personally I tend to use method # 2

---

<div class="post-metadata">

**Author:** ![huang\_zhimin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/54ee81/32.png) [@huang\_zhimin](https://www.ruby-forum.com/u/huang_zhimin)\
**Post date:** [June 21, 2007, 6:16am UTC](https://www.ruby-forum.com/t/question-about-form/107387/4 "2007-06-21T06:16:16Z")

</div>

I got it.

\<% form\_tag :action =\> “destroy” do %\>

  
\<% for category in @categories %\>  
  
  
  
\<% end %\>  

| \<%= radio\_button ‘category’, ‘id’, category.id  
%\>\<%=  
h category.name %\> |

  
\<%= submit\_to\_remote ‘edit’, ‘Edit’, :update =\> ‘category’, :url =\>  
{  
:action =\> ‘edit’ } %\>  
\<%= submit\_tag ‘Delete’ %\>  
\<% end %\>

edit button is submit\_to\_remote which is asynchronized and delete button  
is  
submit\_tag that will refresh the whole page

On 6/21/07, jemminger [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jun 20, 10:30 pm, "huang zhimin" wrote:
> 
> >

–

> **[CodeLineStatistics](https://sourceforge.net/projects/mycodeline/)**
>
> Download CodeLineStatistics for free. The code line statistics takes files and directories from GUI, counts the total files, total sizes of files, total lines, lines of codes, lines of comments and lines of blanks in the files, displays the results...
