# Multiple forms for same model - DOM id collision?

**URL:** <https://www.ruby-forum.com/t/multiple-forms-for-same-model-dom-id-collision/116977>\
**Category:** Rails\
**Created:** [October 11, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/multiple-forms-for-same-model-dom-id-collision/116977 "2007-10-11T20:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 11, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/multiple-forms-for-same-model-dom-id-collision/116977/1 "2007-10-11T20:18:27Z")

</div>

I’m hoping someone can point me to what the “best practice” is…

The basic scenario is a page with two AJAX forms for the same model.  
One is  
to create a new object, while another is to edit an existing object of  
the  
same model. For example, if you had a social networking site, you might  
have a page where you can edit your school information as well as add  
school  
information.

The problem I’m running into is that if I use form\_for, I end up with  
two  
forms whose children have the same DOM ids. I know I can avoid this by  
using form tag helpers like text\_field\_tag, but I’m wondering if there  
is a  
more elegant solution to this problem.

It seems like this would be a fairly common issue, but for some reason I  
can’t find anything about it.

## Thanks!

View this message in context:  
[http://www.nabble.com/Multiple-forms-for-same-model---DOM-id-collision--tf4609106.html#a13161720](http://www.nabble.com/Multiple-forms-for-same-model---DOM-id-collision--tf4609106.html#a13161720)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 11, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/multiple-forms-for-same-model-dom-id-collision/116977/2 "2007-10-11T20:41:20Z")

</div>

On 10/11/07, dw [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem I’m running into is that if I use form\_for, I end up with two  
> forms whose children have the same DOM ids. I know I can avoid this by  
> using form tag helpers like text\_field\_tag, but I’m wondering if there is a  
> more elegant solution to this problem.
> 
> It seems like this would be a fairly common issue, but for some reason I  
> can’t find anything about it.

What I’ve done is to use different object names in form\_remote\_for,  
and then pass that name as a parameter on the form url, so I can point  
to the right parameter to pick up the values in the controller. Kind  
of sub-elegant, but it works and it’s not too difficult to code up.  
You could even dispense with the extra parameter and just hunt through  
the params hash looking for a prefix.

It would be nice the the form builder let you specify an id prefix…
