# Submitting forms help

**URL:** <https://www.ruby-forum.com/t/submitting-forms-help/57294>\
**Category:** Rails\
**Created:** [April 9, 2006, 5:42am UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294 "2006-04-09T05:42:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [April 9, 2006, 5:42am UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294/1 "2006-04-09T05:42:58Z")

</div>

I cant seem to figure this problem out and i was hoping someone could  
help  
me out.

I have a page with a list of forms. I would like the user to be able to  
submit each form individually, or submit them all at once, to a  
different  
action (bascially, one that will do batch processing of all the forms).

Is this possble? Please help.

---

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [April 9, 2006, 6:07am UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294/2 "2006-04-09T06:07:06Z")

</div>

I think you can only submit one form at a time. But there is a solution.

Make your whole page one big form that submits to a particular action.

For each “sub-form” make a button with a unique name. tags or \<input type=button name="little\_form\_1\>.  
You don’t use submit tags for this.

For the entire form make a button with a unique name.

In the action that will process the form you will make a if else  
statement

if params[:all\_forms]

elseif params[:little\_form\_1]

end

The above syntax may be a bit suspect but I’ve used something like  
this before. I think it is nice an clean. I’ve found that it is best  
if forms submit their data back to the same action that created the  
form. This makes life easier. It also helps a lot with validation and  
redirects.

Peter

---

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [April 10, 2006, 1:17am UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294/3 "2006-04-10T01:17:57Z")

</div>

i had a different idea that i’m trying to get right. Each sub form is  
using  
form\_remote\_tag to make an ajax call onsubmit. What i did was create a  
javascript function that loops through all the forms and calls  
document.forms[i].submit()

However, its not acting as if the person clicked the submit button for  
each  
form. I have :loading and :complete attributes set for each subform  
that  
shows the user that the form was submitted and the server result, i’d  
like  
each of these to be triggered when calling document.forms[i].submit()  
which  
i thought it would since they are triggered with the onsubmit event.

Am i missing something? Please help.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [April 10, 2006, 4:59am UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294/4 "2006-04-10T04:59:10Z")

</div>

On 4/9/06, Manish S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i had a different idea that i’m trying to get right. Each sub form is using  
> form\_remote\_tag to make an ajax call onsubmit. What i did was create a  
> javascript function that loops through all the forms and calls  
> document.forms [i].submit()

That is an interesting idea but I’d stay away from it since a simpler,  
bug-free solution exists. JavaScript is hard work.

> From what you’ve written it is possible that you have nested   
> tags? Is this true?

> However, its not acting as if the person clicked the submit button for each  
> form. I have :loading and :complete attributes set for each subform that  
> shows the user that the form was submitted and the server result, i’d like  
> each of these to be triggered when calling document.forms[i].submit() which  
> i thought it would since they are triggered with the onsubmit event.

> document.forms[i].submit()

Instead of this, what you really want to do is simulate a click event  
on each submit button. Or something. Or you want to call with  
JavaScript the same function you have in the onclick attribute of each  
form submit. Things are getting complicated!

Good luck.

Peter

---

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [April 10, 2006, 2:42pm UTC](https://www.ruby-forum.com/t/submitting-forms-help/57294/5 "2006-04-10T14:42:40Z")

</div>

Manish S. wrote:

> i had a different idea that i’m trying to get right. Each sub form is  
> using form\_remote\_tag to make an ajax call onsubmit. What i did was  
> create a javascript function that loops through all the forms and calls  
> document.forms [i].submit()

If you’re going to post using AJAX then perhaps you can use  
submit\_to\_remote and its :submit option. This allows you to  
specify a div element that encloses the named elements that  
you want posted for each submit button. No need for any forms.

–  
We develop, watch us RoR, in numbers too big to ignore.
