Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Ajax Forms And Identity Theft

When using the FormHelper.FormTag(...) in Monorail you can simply do something like this:

<?brail output Form.FormTag({@action:"edit"}) ?>

This will render something like this:

<form id="form1" action="edit.rails" [other attributes]>

Usually I am diligent about naming/id-ing my html elements, especially those which are obvious containers such as divs, fieldsets, forms. However, I had placed a <form/> tag inside an view which would be slurped into my page via MonoRails's Javascript generation.

When I performed a submit the first time inside my form, the action was called and things were great. The problem was when I tried to perform another action inside the same area. Instead of firing the form via ajax I would actually render the raw javascript which the JS generator responded with.

At first, I thought since my form was getting added dynamically to the DOM the submit event of the form wasn't getting subscribed. I am using jQuery so I looked at the livequery plugin to handle this. However something bothered me about this so I looked again at my view source. I noticed that the <form/> that was brought in had an id of 'form1' as Monorail creates and id for you when you have not specified an id explicitly. The problem, of coursse, was that I had another 'form1'  on my page, resulting in duplicate ids, confusing the Form plugin and posting the data via standard request.

The simple fix was to explicitly define ids on my form elements and all is good. Good reminder to be more disciplined with my page creation.

Posted 03-24-2008 12:34 AM by Michael Nichols
Filed under: ,



Michael Breen wrote re: Ajax Forms And Identity Theft
on 03-24-2008 7:21 AM

Thanks for the tip. I have a quick question as I ma just diving into MonoRail using the Brail view engine.

Why are you using "<? brail output ?>" instead of "<%  %>"? Is there a difference?

Michael Breen wrote re: Ajax Forms And Identity Theft
on 03-24-2008 7:01 PM

Found it in the docs (where I should have looked in the first place!)

Mike wrote re: Ajax Forms And Identity Theft
on 03-24-2008 7:37 PM


My style has just settled on using the "<?brail" syntax. Glad you found what you were looking for.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)