# Observe two forms, submit both in one action?

**URL:** <https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708>\
**Category:** Rails\
**Created:** [November 20, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708 "2006-11-20T16:37:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhubarbcrumble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rhubarbcrumble](https://www.ruby-forum.com/u/rhubarbcrumble)\
**Post date:** [November 20, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708/1 "2006-11-20T16:37:14Z")

</div>

Hi All,

I currently have a RoR website that lists music gigs. By default it  
displays all results in the database over several pages, but the results  
can be filtered using a simple form - it may be easier to see it at  
[http://www.gigcatcher.com](http://www.gigcatcher.com)

So far, this all works fine and the form is watched every second for  
changes by observe\_form.

The problem begins when I try to add a drop-down list… Unless no  
frequency is set on observe\_form, the behaviour of the drop-down is not  
really what I want (i.e. just hovering over a selection submits the  
form).

What I would like:  
The existing search boxes for artist, venue and town - observed every  
second  
A drop-down list (for gigs added in the last x days) - submitted on  
selection

Is it possible to have two forms on the page, observed separately but  
which each submit the combined data from both?

Cheers!

- Sandy

---

<div class="post-metadata">

**Author:** ![rhubarbcrumble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rhubarbcrumble](https://www.ruby-forum.com/u/rhubarbcrumble)\
**Post date:** [November 20, 2006, 5:07pm UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708/2 "2006-11-20T17:07:59Z")

</div>

Sandy T. wrote:

> Hi All,  
> Is it possible to have two forms on the page, observed separately but  
> which each submit the combined data from both?  
> Cheers!
> 
> - Sandy

Try use something like :with=\>“Form.serialize(‘form1\_id’) &  
Form.serialize(‘form2\_id’)”

Regards  
Simo  
addsw.it

---

<div class="post-metadata">

**Author:** ![rhubarbcrumble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rhubarbcrumble](https://www.ruby-forum.com/u/rhubarbcrumble)\
**Post date:** [November 22, 2006, 9:37am UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708/3 "2006-11-22T09:37:24Z")

</div>

just to fix, the correct syntax is  
:with=\>“Form.serialize(‘form1\_id’) + ‘&’+ Form.serialize(‘form2\_id’)”

You can also use only one form, using different observe\_field (for  
artist, venue, town and gigs ) with option  
:with=\>“data=Form.serialize(‘form1\_id’)”

Simo  
addsw.it

Sandy T. wrote:

> > Try use something like :with=\>“Form.serialize(‘form1\_id’) &  
> > Form.serialize(‘form2\_id’)”
> 
> Hmm… I had a go at that but no luck, I’ve gone with the odd behaviour  
> on the drop-down as it only seems to affect firefox from what I can see.  
> I reduced the observe time to 2 seconds also which makes it less  
> noticeable.
> 
> Shout if anyone knows a better way to do this…
> 
> Cheers,
> 
> - Sandy

---

<div class="post-metadata">

**Author:** ![rhubarbcrumble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rhubarbcrumble](https://www.ruby-forum.com/u/rhubarbcrumble)\
**Post date:** [November 20, 2006, 10:33pm UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708/4 "2006-11-20T22:33:05Z")

</div>

> Try use something like :with=\>“Form.serialize(‘form1\_id’) &  
> Form.serialize(‘form2\_id’)”

Hmm… I had a go at that but no luck, I’ve gone with the odd behaviour  
on the drop-down as it only seems to affect firefox from what I can see.  
I reduced the observe time to 2 seconds also which makes it less  
noticeable.

Shout if anyone knows a better way to do this…

Cheers,

- Sandy

---

<div class="post-metadata">

**Author:** ![rhubarbcrumble](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@rhubarbcrumble](https://www.ruby-forum.com/u/rhubarbcrumble)\
**Post date:** [November 23, 2006, 1:24pm UTC](https://www.ruby-forum.com/t/observe-two-forms-submit-both-in-one-action/76708/5 "2006-11-23T13:24:32Z")

</div>

Simo wrote:

> just to fix, the correct syntax is  
> :with=\>“Form.serialize(‘form1\_id’) + ‘&’+ Form.serialize(‘form2\_id’)”
> 
> You can also use only one form, using different observe\_field (for  
> artist, venue, town and gigs ) with option  
> :with=\>“data=Form.serialize(‘form1\_id’)”
> 
> Simo  
> addsw.it

Cheers Simo! much appreciated - I now have two forms that submit with  
data from both.

If anyone is wanting the same thing, I just created two forms and two  
observe\_form functions (one observing by time and one observing on  
select, for the drop-downs). For each observe\_form I included the  
following line:

:with=\>“data=Form.serialize(‘form1\_id’) + ‘&’ +  
Form.serialize(‘form2\_id’)”

(I had to combine the syntax from above a little to include ‘data=’)

Cheers!

- Sandy
