Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jquery submit multiple forms

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...