tags:

views:

237

answers:

5

Hi,

I have a form with a submit button. I have called a function on click of submit button.

function actionPage(form1)
{
  form1.action="action1.php";
  form1.submit();
  return(true);
}

Now i want that the form data should be submitted to two different pages. These pages are on different servers.

I know that we can send the data to a particular page according to the conditions but i am not sure whether we can submit to two different pages at the same time i.e:

function actionPage(form1)
{
  form1.action="action1.php";
  form1.submit();
  return(true);
  form1.action="action2.php";
  form1.submit();
  return(true);

}

Right now it is showing action1.php

Please guide me on this .

Regards,

Pankaj

+4  A: 

you cannot do it using simple form post submit. but you can do it using AJAX.

as you soon as you call submit() fn, the data from the form is posted to the action url page. hence you might end up page being loaded.

coder
How do shopping cart software manage this? I mean when you click on checkout your info is saved in the database and you are also directed to a payment gateway. Even if you are not able to complete the payment gateway part, your ordering information is saved. There are clearly 2 things happening on the same click - some data is being inserted in a database and a form is being submitted.
Vinayak
vinayak, you need to understand html form post first. what you are saying is technically one form post. once form is posted, data is stored and server sends the browser for redirection based on the server side code. not based on the client side code. i would suggest you to learn HTML form and server side redirection
coder
+3  A: 

You cannot. You could submit data to multiple places using an XmlHttpRequest.

marr75
+2  A: 

You can't submit the form that way to multiple places. You can do it on the client side via AJAX, or you can post can have the form post to a page that will submit the data wherever else it needs to go. With the AJAX approach, you will run into problems submitting to a different domain due to the same origin policy. I would suggest using cURL on the server side to send the data to other domains.

Greg Shackles
A: 

Just as simple as this:

<form name=f1 type=post action=''> 
    <input type='submit' value='first url' onclick="f1.action='/save'">
    <input type='submit' value='second url' onclick="f1.action='/process'">
</form>

Taken from: http://www.plus2net.com/html_tutorial/submit-two.php

phil pirozhkov
Ooops sorry, misunderstood the questionIt could be much simpler and strightforward to call one action from another on server side rather than submitting the form twice.
phil pirozhkov
A: 

Could someone post some AJAX or a link to an AJAX script that does this?