简体   繁体   中英

Two different actions on form submit

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 ie:

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

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.

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM