最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Two different actions on form submit - Stack Overflow

programmeradmin4浏览0评论

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

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

Share Improve this question edited Jul 8, 2014 at 5:37 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Mar 5, 2010 at 5:52 Pankaj KhuranaPankaj Khurana 3,27110 gold badges51 silver badges79 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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./html_tutorial/submit-two.php

发布评论

评论列表(0)

  1. 暂无评论