Forum: Ruby on Rails form_remote_tag can only have one submit button?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrew C. (Guest)
on 2006-04-10 19:26
(Received via mailing list)
I setup a form_remote_tag with several submit buttons, all of them share
the same name
( 'do_action' ) and their values differ.

eg.
button1 named do_action with value ACTION1
button2 named do_action with value ACTION2,
etc


No matter which button I press the value passed is always the one
defined for the first of these buttons ( the correct value associated
with the pressed button is not passed to the controller ).

This behavior does not occur with a regular form_tag, which works as it
should passing the value associated with the pressed button.

Anyone have any insight into this, surely this is not intended behavior?

-Andy
Roberto S. (Guest)
on 2006-04-10 19:35
(Received via mailing list)
It's the way prototype serializes the form fields.  You need to hack
something with hidden form fields which get populated via javascript
when
one of your  submit buttons get pressed.
Chris H. (Guest)
on 2006-04-10 19:53
(Received via mailing list)
ajax forms don't work the same as standard html forms, at least as far
as
submission to the server goes.

basically, in the end, the form data gets serialized into a parameter
string

field1=this&field2=that&field3=foobar

if you have 2 form fields (this includes buttons) with the same name,
you
can see what happens.

field1=this&field1=that


here is a test (save to your myapp/public directory:

<html>
<head>
<script type="text/javascript" src="/javascripts/prototype.js"></script>
</head>
<form id="testform" method="post">
<input type="submit" name="do_action" value="1"/>
<input type="submit" name="do_action" value="2"/>
</form>
<script type="text/javascript">
document.write("<code>" + Form.serialize("testform") + "</code>");
</script>

load it in the browser and you can see what prototype does to the form
in
order to prepare the request

Chris
Andrew C. (Guest)
on 2006-04-10 20:31
Gothca, thanks for the explanation guys.

-Andy



Chris H. wrote:
> ajax forms don't work the same as standard html forms, at least as far
> as
> submission to the server goes.
>
> basically, in the end, the form data gets serialized into a parameter
> string
>
> field1=this&field2=that&field3=foobar
>
> if you have 2 form fields (this includes buttons) with the same name,
> you
> can see what happens.
>
> field1=this&field1=that
>
>
> here is a test (save to your myapp/public directory:
>
> <html>
> <head>
> <script type="text/javascript" src="/javascripts/prototype.js"></script>
> </head>
> <form id="testform" method="post">
> <input type="submit" name="do_action" value="1"/>
> <input type="submit" name="do_action" value="2"/>
> </form>
> <script type="text/javascript">
> document.write("<code>" + Form.serialize("testform") + "</code>");
> </script>
>
> load it in the browser and you can see what prototype does to the form
> in
> order to prepare the request
>
> Chris
This topic is locked and can not be replied to.