i am using two forms in a jsp page.i want to submit form2 but it needs first form1 to be submitted then second form will be submitted.please help me how to only submit form2 without submitting form1 ..thankyou :)
我在jsp页面中使用两个表单。我想提交form2但它需要先提交form1然后提交第二个表单。请帮助我如何只提交form2而不提交form1 ..thankyou :)
<html:form action="action1">
<html:submit property=method><bean:message key="userform.login"/></html:submit>
</html:form>
<html:form action="action2">
<html:submit property=method><bean:message key="userform.contactus"/></html:submit></html:form>
2 个解决方案
#1
0
You are not going to be able to submit a form without leaving the page unless you use :
除非您使用以下内容,否则您无法在不离开页面的情况下提交表单:
Ajax ( as suggested ) - and on the 'success' return post form 2
Ajax(如建议的那样) - 以及'成功'返回表格2
or an Iframe
或者iframe
Iframe - post into an iframe on the page, the iframe page can trigger the posting of form2 (if form1 post is successful) by using javascript 'parent.form2.submit()'
iframe - 发布到页面上的iframe,iframe页面可以通过使用javascript'parent.form2.submit()'触发form2的发布(如果form1发布成功)
#2
2
You would need to submit one form via Ajax, and in the callback, do whatever you need to with the results of submitting the first form. Then the second form can be submitted normally.
您需要通过Ajax提交一个表单,并在回调中,根据提交第一个表单的结果执行您需要的任何操作。然后可以正常提交第二个表格。
IMO your usecase seems a little twisted: you shouldn't need to be logged in to "contact us" first of all. If the goal is to include user info in the "contact us" form, then (a) why show a "contact us" link before you can use it, and/or (b) just do normal "you must be logged in" processing and don't worry about the convolutions of doing what you're doing.
IMO你的用例似乎有点扭曲:你不应该首先登录“联系我们”。如果目标是在“联系我们”表单中包含用户信息,则(a)为什么在您可以使用它之前显示“联系我们”链接,和/或(b)只做正常“您必须登录”处理,不要担心做你正在做的事情的卷积。
Alternatively, have an additional login form on the "contact us" page and require it as part of the form validation, and skip all of these issues, create a smoother user experience, and make your development that much easier.
或者,在“联系我们”页面上添加一个额外的登录表单,并将其作为表单验证的一部分,并跳过所有这些问题,创建更流畅的用户体验,并使您的开发更容易。
#1
0
You are not going to be able to submit a form without leaving the page unless you use :
除非您使用以下内容,否则您无法在不离开页面的情况下提交表单:
Ajax ( as suggested ) - and on the 'success' return post form 2
Ajax(如建议的那样) - 以及'成功'返回表格2
or an Iframe
或者iframe
Iframe - post into an iframe on the page, the iframe page can trigger the posting of form2 (if form1 post is successful) by using javascript 'parent.form2.submit()'
iframe - 发布到页面上的iframe,iframe页面可以通过使用javascript'parent.form2.submit()'触发form2的发布(如果form1发布成功)
#2
2
You would need to submit one form via Ajax, and in the callback, do whatever you need to with the results of submitting the first form. Then the second form can be submitted normally.
您需要通过Ajax提交一个表单,并在回调中,根据提交第一个表单的结果执行您需要的任何操作。然后可以正常提交第二个表格。
IMO your usecase seems a little twisted: you shouldn't need to be logged in to "contact us" first of all. If the goal is to include user info in the "contact us" form, then (a) why show a "contact us" link before you can use it, and/or (b) just do normal "you must be logged in" processing and don't worry about the convolutions of doing what you're doing.
IMO你的用例似乎有点扭曲:你不应该首先登录“联系我们”。如果目标是在“联系我们”表单中包含用户信息,则(a)为什么在您可以使用它之前显示“联系我们”链接,和/或(b)只做正常“您必须登录”处理,不要担心做你正在做的事情的卷积。
Alternatively, have an additional login form on the "contact us" page and require it as part of the form validation, and skip all of these issues, create a smoother user experience, and make your development that much easier.
或者,在“联系我们”页面上添加一个额外的登录表单,并将其作为表单验证的一部分,并跳过所有这些问题,创建更流畅的用户体验,并使您的开发更容易。