I have two forms in my rails app. They both exist in separate tabs and I when I submit one form I want the data in the other form to be saved as well. How should I do that? Or Is there a better way of doing this instead of using two separate forms? Is there a better way to spread a long form into multiple tabs and when I press submit all the data from all the tabs should reach my action. Thanks.
Share
You can expand a single form to cover all elements of both forms.
This is perfectly ok, as long as the form tags fit validly into the X/HTML.
The only thing to consider is if there will ever be another form inside that area that will need to go to another action. For example, if you add a third tab, in between the other two, that will have a different action.
You don’t want to end up like:
In that case, it would be better to consolidate the two forms at submit time using JavaScript.
jQuery (jquery.com) would make this pretty easy. For example, you could serialize both forms, and then concatenate them and send the result to the server via post or get.
See http://docs.jquery.com/Ajax/serialize.
There might be better ways to do this, but I can’t think of any off the top of my head.