faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

41 of 59 people (69%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Can I use Javascript to submit two forms simultaneously from the same page?
How can I run two cgi scripts with a single form submission?

Aug 3rd, 1999 09:09
Teodor Cimpoesu, Nathan Wallace,


browsers only submit a form at a time, either by request of the user or
programmatically.  So you can't use Javascript to submit two forms
simultaneously.

What you may want to do is to submit a form to a page which code submit
the form data to those other two CGI addresses.  You may find here an
HTTP PHP class that you may use to POST as much forms as you like:

    http://phpclasses.UpperDesign.com/browse.html?package=3

You could just have the first CGI submit to the second CGI? That would
be a lot simpler. I don't even know if it's possible to submit to
multiple CGI's.  I don't think it is, but if the CGI's return a 204 No
Content status, it may be possible.

Errata:
you can do it this way
<body>
<form name='f1' action="p1.php" method="post">
<input type="hidden" name="p1">
<input type="hidden" name="p2">
<!-- so on -->
</form>
 
<form name='f2' action="p2.php" method="post">
<input type="text" name="p1" value="[some text]">
<!-- other form fields -->
<input type="button" value="go" onClick="doSubmit()">
</form>

<script><!--
 function doSubmit()
 {
  document.f1.p1.value = "my_hidden_param1";
  document.f1.p1.value = "my_hidden_param2";
  document.f1.submit();
  document.f2.submit();
 }
//-->
</script>
</body>
Depending which reply you want to use, switch
between f1.submit() and f2.submit() calls.