0

I am attempting to create an HTML form, that of which uses the submit button, to email me the data that has been entered (have that part covered) but also send the data to another external page (that can handle this request).

I can have it working by doing:

<form name="contactform" method="post" action="http://somesite.com/page.php">

But, I also need it to submit to a local page (form.php) at the same time.

I have tried javascript, by doing this for the submit button:

  <input type="submit" value="Submit" onclick="return doSubmit();"> 

With this code in the source:

function doSubmit()
{
    document.contactform.action = "form.php";
    document.contactform.submit(); 
    document.contactform.action = "http://somewebsite.com/page.php";
    document.contactform.submit(); 
    return true;
}

But when I do this, the information is not sent to my email, and instead of displaying the result on form.php the page is refreshed.

Any ideas on how I can make this work in a simple way?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Dante
  • 59
  • 2
  • 10

3 Answers3

1

You can't submit to multiple actions at the same time as the browser can only load one request per window at a time by design. Some solutions include:

  1. Just do the email handling with the same server script that does the form input handling
  2. Send the form data to the email script via ajax and then submit the form normally on completion, e.g.
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
0

Obviously you cannot submit two forms. You can try either of these two things:

  • Make one of them an ajax request, and set it to be executed before submit.
  • Execute the second php file directly from the first one in the server side.
Rayshawn
  • 2,603
  • 3
  • 27
  • 46
loxxy
  • 12,990
  • 2
  • 25
  • 56
0

I would recommend adding/altering a function in your php script. Then you can do whatever you like with the posted data.

enkdr
  • 363
  • 5
  • 15