# Form w/ two submit buttons

**URL:** <https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644>\
**Category:** Rails\
**Created:** [June 17, 2008, 2:17am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644 "2008-06-17T02:17:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 2:17am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/1 "2008-06-17T02:17:38Z")

</div>

I want to have a form with a save and a cancel button. According to  
several  
Web site I should be able to put these two tags shown below in my form:

I expect to be able to determine which button is clicked by testing  
'params[:savecancel] == ‘Cancel’. However, it doesn’t work, both values  
are  
in the request. I.e., Firebug reports the request as:

\_method=put&comment%5Bsummary%5D=Comment&comment%5Bdescription%5D=description4&tag\_names=&savecancel=Save&savecancel=Cancel&previous\_page=%2Ftasks%2Fsearch%3Fpage%3D2

And Webrick reports:

Parameters: {“previous\_page”=\>"/tasks/search?page=2",  
“\_method”=\>“put”, “action”=\>“update”, “savecancel”=\>“Save”, “id”=\>“532”,  
“controller”=\>“comments”, “tag\_names”=\>"", “taggable\_id”=\>“531”,  
“comment”=\>{“summary”=\>“Comment”, “description”=\>“description4”}}

Regardless of which button is actually clicked. Suggestions? Is  
Prototype.js  
messing this up?

TIA,  
Jeffrey

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 2:20am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/2 "2008-06-17T02:20:05Z")

</div>

Is this in an ajax form?

The ajax form will only detect the first submit tag.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 2:41am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/3 "2008-06-17T02:41:21Z")

</div>

Quoting Ryan B. (Radar) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Is this in an ajax form?
> 
> The ajax form will only detect the first submit tag.

Is a remote\_form\_for an AJAX form? If so, yes this is.

Jeffrey

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 2:51am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/4 "2008-06-17T02:51:53Z")

</div>

Yup. There’s your problem.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 3:14am UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/5 "2008-06-17T03:14:08Z")

</div>

On Jun 16, 2008, at 5:16 PM, Jeffrey L. Taylor wrote:

> values are  
> “id”=\>“532”, “controller”=\>“comments”, “tag\_names”=\>"",  
> “taggable\_id”=\>“531”, “comment”=\>{“summary”=\>“Comment”,  
> “description”=\>“description4”}}
> 
> Regardless of which button is actually clicked. Suggestions? Is  
> Prototype.js  
> messing this up?

I found the same problem with image buttons. Prototype does not pass  
along the .x typically submitted by a normal HTML form.

Suggestions? No one has been able to offer me any concrete ones. It’s  
a severe limitation in prototype (or perhaps XHR in general).

– gw

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 3:24pm UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/6 "2008-06-17T15:24:36Z")

</div>

On 17 Jun 2008, at 03:07, Greg W. wrote:

> > values are  
> > “\_method”=\>“put”, “action”=\>“update”, “savecancel”=\>“Save”,
> 
> Suggestions? No one has been able to offer me any concrete ones. It’s  
> a severe limitation in prototype (or perhaps XHR in general).

It’s something that you’ll have on all ajax frameworks, there are a  
few possible solutions to the problem:

1. 

[http://www.rails.cz/articles/2007/07/13/ajax-forms-with-multiple-submit-buttons-bug](http://www.rails.cz/articles/2007/07/13/ajax-forms-with-multiple-submit-buttons-bug)  
2. A cancel button is not something that should submit the form values  
in the first place, cancelling is just an action and not an update, so  
it’s better to just keep it a (either normal or ajax) link, i.e. . You can then style it to appear just like your submit button.

 

Best regards

 

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![Jeffrey\_LSTaylor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ee7513/32.png) [@Jeffrey\_LSTaylor](https://www.ruby-forum.com/u/Jeffrey_LSTaylor)\
**Post date:** [June 17, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/form-w-two-submit-buttons/140644/7 "2008-06-17T15:35:54Z")

</div>

Quoting Jeffrey L. Taylor [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Quoting Ryan B. (Radar) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Is this in an ajax form?
> > 
> > The ajax form will only detect the first submit tag.
> 
> Is a remote\_form\_for an AJAX form? If so, yes this is.

I have been looking at [del.icio.us](http://del.icio.us) which is where I stole the idea from.  
Using the Firebug extension for Firefox I can see the HTML and GET/POST  
requests and the responses. It’s interesting. The “form” isn’t really  
an  
HTML form, it’s a bunch of input tags. The cancel button does not make  
a  
request to the server. And the “form” isn’t replacing the content being  
altered, it’s still there but hidden, i.e., ‘display: none’  
style/attribute.  
Should be easy to delete the “form” and unhide the original content with  
some  
JavaScript. I don’t understand it all, but I have enough to explore.  
When I  
have something working I’ll write it up on my blog and post a link here.

Jeffrey
