Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

How do I submit multiple forms with one action call

I have two forms that I need to submit at the same time.  How can I do this?
0
97g8r
Asked:
97g8r
  • 5
  • 2
  • 2
  • +3
1 Solution
 
CyberSoftCommented:
As far as I know you cannot submit two forms at the same time if you're planning to do it on the same page? Why because the browser can only go to one place at a time. However, if you wish to submit the two forms and they don't necessarily need to display anything once done then you can create popup windows for the forms and then put a check in each one that once completed causes them to close and take your original browser to another predetermines page (that perhaps tells you what has happened).

Hope that kind of makes sense.

Regards,
CyberSoft
0
 
CyberSoftCommented:
Here's an example why it won't work. Try it out for yourself. It will try and first go to www.yahoo.com (where the first form submits to) and then tryand go to www.cnn.com (where the second form submits) to.

But the last form being submitted is the one that the browser will attempt to go to. As soon as the second submit line is called and the browser hasn't already reached www.yahoo.com that navigation is cancelled and the browser then goes to www.cnn.com

<!-- start code -->

<html>
<head>
     <title>Submit two forms at same time</title>
     <script language="JavaScript">
     function submitForms()
     {
          document.frm1.submit()
          document.frm2.submit()
     }
     </script>
</head>

<body>

<form id="frm1" name="frm1" method="post" action="http://www.yahoo.com/">
     <input type="hidden" name="hiddenField1" value="dummy">
</form>

<form id="frm2" name="frm2" method="post" action="http://www.cnn.com/">
     <input type="hidden" name="hiddenField1" value="dummy">
</form>

<form id="frmSubmit" name="frmSubmit">
     <input type="button" name="submit" value="submit both forms" onclick="submitForms();">
</form>

</body>
</html>

<!-- end code -->
0
 
MCMCommented:
In CyberSoft's example, the 1st submit request may be sent to yahoo. So, if you were trying to update a database with the contents of the first form and of the second form, the 1st submit request might have the desired effect, even though the browser would never see the response.

That said, though, sending two requests at once is not what browsers were designed to do -- so even if you found a double-submit trick that worked, it would be a cluge. Why is it so important to have two forms? It's hard to imagine a situation where this is totally necessary. Maybe you could describe what you are trying to do more generally, and someone can propose an alternative method for dealing with the problem.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
isaranaCommented:
You could try combining 2 forms and submit as one form by having a third form with invisible fields, copy the contents of the first two forms and submit...


<SCRIPT LANGUAGE="JavaScript"><!--
  function copydata() {
      document.formC.one.value = document.formA.one.value;
      document.formC.two.value = document.formB.two.value;
      document.formC.submit();
      return false;
  }
  //--></SCRIPT>

  <FORM NAME="formA" onSubmit="return copydata()">
  Enter your text 1: <INPUT TYPE="text" NAME="one">
  <P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
  </FORM>

  <FORM NAME="formB" onSubmit="return copydata()">
  Enter text 2: <INPUT TYPE="text" NAME="two">
  <P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
  </FORM>

  <FORM NAME="formC">
  <INPUT TYPE="HIDDEN" NAME="one">
  <INPUT TYPE="HIDDEN" NAME="two">
  </FORM>
0
 
labcoatCommented:
isarana's comment will definately work if both forms are being submitted to the same URL and the server-side code is set up to accept the two forms as one.

--labcoat
0
 
CyberSoftCommented:
I assumed since 97g8r wabted two separate forms to be submitted that their content was not related and they needed to be submitted to different pages for processing - hence I didn't provide a combined form solutoin as isarana did.

97g8r - can you give us more info?

Regards,
CyberSoft
0
 
labcoatCommented:
CyberSoft, that is probably the case.

You could also submit the forms to two seperate server-side pages in two seperate hidden iframes in the newer browsers (similar to the popup window comment above).

--labcoat
0
 
CyberSoftCommented:
Labcoat, that's a good idea as well - didn't think about hidden frames when I wrote the popup windows as a solution.

Wonder if 97g8r is even reading this thread since he/she hasn't responded since their original post?

Regards,
CyberSoft
0
 
ahosangCommented:
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
ahosangCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ - NO REFUND
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 
CyberSoftCommented:
I guess isarana, labcoat and myself put pretty much equal effort into this question? Split points? Suggestions?

Regards,
Cybersoft
0
 
NetminderCommented:
Cybersoft,

In the absence of comments from the asker, it's impossible to tell which comment might have helped. While it's my own PERSONAL opinion that effort should be rewarded, as a Moderator/Admin, we're not in a position to do that.

Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now