jquery提交多个表单

发布于 2024-08-23 20:22:13 字数 327 浏览 5 评论 0原文

我一页上有 4 个表格。根据用户的选择,表格 1 必须与表格 2,3 或 4 一起提交。

jQuery 的 .submit() 只能执行一种表单。

ajax 发布表单不是一个选项,

我只能考虑将表单 1 的内容添加到另一个表单,就像提交后一个表单之前一样。

还有其他方法吗?

<块引用>

更新:

4种形式而不是的原因 只有 1 是我正在验证每个 独立形成,因为 2 3 个表单从视图中隐藏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆沫 2024-08-30 20:22:13

如果一种表单依赖于其他两种表单,那么听起来它们实际上是同一表单的一部分,并且后端应该只找出该大型表单的哪些部分(具有不同的数据集,但针对一种表单)需要。同样,最好不要单独依赖 javascript,因此这样做可以自动为您提供更强大的解决方案。

更新 如果您有多个仅共享数据的表单(例如它们可以更改 form3 所需的 form1 和 form2 上的数据),那么将这些共享的内容放在其中会更稳定,尤其是在验证方面隐藏元素并将表单分开。让用户输入将要提交和使用的数据,然后将其隐藏在视图中并不是最佳选择,因为他们更容易犯输入错误(他们无法轻松查看,而且他们可能不明白数据将全部提交)。使用<代码><共享信息的 input type="hidden" /> 可以缓解这种情况,因为他们无法意外地更改它。 (或者将其存储在会话中或您想要的任何内容中。重点是,防止他们更改您将依赖的信息,并且他们无法轻易发现其中的错误。)

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

平安喜乐 2024-08-30 20:22:13

由于表单已提交并且您正在离开该页面,因此您可以在提交之前删除不必要的字段。只需要一份表格。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文