Is to possible to submit two forms simultaneously?

前端 未结 6 562
说谎
说谎 2020-12-21 13:42

Is to possible to submit two forms simultaneously with either javascript or a submit button?

Form structure is ok something like this:

相关标签:
6条回答
  • 2020-12-21 14:12

    The purpose of the <form> tag is to encapsulate the information that the browser sends to the server.

    The only way to work around that would be to have some JavaScript that walks through the DOM and pulls info from one form and puts it in the other when the user clicks Submit.

    0 讨论(0)
  • 2020-12-21 14:15

    No, this is not possible. You can create a third hidden form, that will serialize fields from both of them.

    If you can use jQuery:

    var str1 = $("form1").serialize();
    var str2 = $("form2").serialize();
    $.post(url, str1 + "&" + str2);
    

    You need to make sure that str1 and str2 aren't empty and of course avoid name conflicts between the two forms.

    0 讨论(0)
  • 2020-12-21 14:16

    Submiting the two form will trigger two call to the posting URL so you will not be able to get the two data at the same time.

    0 讨论(0)
  • 2020-12-21 14:17

    The problem is that submitting a form changes the URL of the page. This means that when one form is submitted, the second form no longer exists in the active page, and cna therefore not be submitted.

    You'll need to submit them over AJAX. Do you use any javascript libraries?

    0 讨论(0)
  • 2020-12-21 14:20

    No, this is not possible.

    Back-up a second and tell us what you're trying to accomplish and why you feel two forms are necessary. There may be a more elegant solution.

    0 讨论(0)
  • 2020-12-21 14:34

    No, its not possible on a single page.

    AJAX submission could be the aswer, as intimated elsewhere, but another possible solution could be to embed the second form with in another page and put that page within an IFrame on the first page.

    Not sure how that would pan out in reality, but may be worth a go try

    0 讨论(0)
提交回复
热议问题