views:

231

answers:

2

Hi,

I have 4 forms on a page. Form 1 must be submitted with either form 2,3 or 4 depending on user selection.

jQuery's .submit() can only do one form.

ajax posting the forms is not an option

i can only think of adding the content of Form 1 to the other form as before submitting the latter form.

is there any other way to do it?

UPDATE:

The reason for the 4 forms instead of just 1 is that I am validating each form independently, since the 2 of the 3 forms are hidden from view.

+2  A: 

If one form relies on two other forms, it sounds like they're really part of the same form, and the backend should just figure out which parts of that one mega-form (with different sets of data, but for one form) that are needed. On a similar note, it's best not to rely on javascript alone anyway, so doing it this way provides you with an automatically more robust solution.

Update If you have multiple forms that are just sharing data (like they can change data on form1 and form2 that form3 needs), it would be more stable, especially in light of validation, to put those shared things in hidden elements and leave the forms separate. Having users enter data that will be submitted and used and then hiding it from view isn't optimal, since they can more easily make entry mistakes (they can't review as easily and they may not understand it will all be submitted). Using < input type="hidden" />s for shared info alleviates this because they won't be able to accidentally change it. (Or store it in the session or whatever you'd like. Point is, prevent them from changing info that you're going to rely upon and they can't easily spot mistakes in.)

D_N
so you say i should just create a mega-form containing all 4 forms and submit everything. and just figure out on the back-end which is which.
Circadian
Yep. If javascript fails, your form doesn't. And any group of inputs that need to be submitted together are essentially one form.
D_N
my problem with the mega-form which i failed to make clear is that i am using the validate plugin and this is kinda tricky when 2 of the 3 forms are hidden.
Circadian
Without more markup/context I can't really offer a solution, but if you mean they're dynamically hidden/shown, that's a job for some input management. If you hide something, you could change the class that validate relies on to something like 'noval-date'/'noval-email', which should take it out of validation, and then strip out that prefix when/if you show it again.
D_N
Updated recommendation.
D_N
my form are independent of each other.form 1 is always to be submitted. one of the forms 2,3 or 4 is submitted with form 1. if form 2 is visible forms 3 and 4 are hidden and so on.validation is added to all the forms, which prevents me from having a mega-form since I will have to add/remove listeners every time a form is show/hidden.i will probably select all inputs from form 1 and add them as hidden to the currently active form when the submit button is pressed. (the thing i was trying to avoid)
Circadian
A: 

Since the form is submitted and you are navigating away from the page you could remove the unnecessary fields before submitting. Only one form will be necessary.

kgiannakakis