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?
<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