开发者

How can I use PHP or JS/HTML to dual post to a URL

开发者 https://www.devze.com 2023-04-06 06:02 出处:网络
I know that it probably isn\'t possible to submit a form from one button to 2 various locations so I was wondering if someone knew of a solution.

I know that it probably isn't possible to submit a form from one button to 2 various locations so I was wondering if someone knew of a solution.

When I click submit on a form I have the following form tag:

<FORM ACTION="http:site.com/servlets/RequestServlet" method="post">

But I want the form to have 2 action pa开发者_StackOverflowrameters. This way as soon as a user fills this form out, submits the form, the form is submitted to a SERVER AND a PHP script that will pull out the parameters submitted by the the form and email the user details about their form submission such as request ID etc.

Over here the Servlet is submitted to so that a record can be made in the network but an email is required to be sent to a user after form submission in-case they need to reference later on to a rep about their request id for further assistance.

How can I achieve the submission to a PHP script in addition to the submission to the Servlet that's already occurring?

NOTE: I cannot modify the Servlet in any way as it does not belong to me. All I want to do as add the email function for a user to later reference their ticket id.


Set a javascript onclick parameter for the submit button. So it will post to the action you set, but also run a function such as:

function secondSubmit() {
  url = "myphpscript.php";
  data = { someData: "data", someOtherData: 2 };

  $.post(url, data, function(returnedData) {
            // can do something on return if you'd like here
         });
}

someData and someOtherData will show up in PHP as $_POST["someData"] and $_POST["someOtherData"]. So basically, you will have the form submit to the first URL via the HTML form, and have the second form submitted via jQuery with this function. Alternatively, you can do both submissions in this function and have the form have no action.

For more info, see here: http://api.jquery.com/jQuery.post/

0

精彩评论

暂无评论...
验证码 换一张
取 消