Form Post

0 views
Skip to first unread message

Exerior

unread,
Feb 14, 2007, 10:53:54 AM2/14/07
to Ruby on Rails: Spinoffs
I am using prototype 1.5

I have a very complex form with lots of data. For example 100 input
fields. Now i need to send these data to the server like it is a
normal form post. The server-side should think the data are sended
with method=post.

Here is a code sample (the real code is two long, so i wrote a code to
demonstrate my problem):


<form id=myInput method=post action=index.php>
<input .... > </form> <!-- many forms -->

<div id=myResult></div>

<script type=\"text/javascript\" language=\"javascript\">
new Ajax.Updater('myResult', 'index.php?action=recieve', { method:
post });
</script>


How do i add the form data to the updater?

Colin Mollenhour

unread,
Feb 14, 2007, 2:21:33 PM2/14/07
to rubyonrail...@googlegroups.com
I'm not clear on whether you have many forms or many inputs, but by far
the easiest solution is to use good ole' HTML markup with a single form.
Be sure to set the name property for every input element that you want
included in the post, you can use arrays [] and hashes [key], even
combinations of the two, or just unique names (if not an array or hash
and not unique, they will be overridden server-side).

<form id="myform">
<input name="data1" ... />
<input name="data2" ... />
<input name="arrayone[]" ... />
<input name="arrayone[]" ... />
<input name="hashone[keyone]" ... />
<input name="hashone[keytwo]" ... />
</form>
<div id="myResult'></div>
<script type="text/javascript">
new Ajax.Updater('myResult','index.php?action=receive',{
parameters: Form.serialize('myform')
});
</script>

Post is the default method so no need to specify. If you *must* have
multiple forms you could join the results using this:
parameters:
['form1id','form2id','form3id'].collect(Form.serialize).join('&')

I love Form.serialize.

Colin

Reply all
Reply to author
Forward
0 new messages