简体   繁体   中英

How To Send Form Data To Two Or More PHP Files?

I have a Form in an HTML page like below that is sending my data to a page at http://www.aaaaaa.com/1st-file.php ...

<form action="http://www.aaaaaa.com/1st-file.php" method="post" enctype="plain" id="theForm">   
<input type="text" name="NAME" value="Some Data" />
<input type="submit" value="Send Data" />
</form>

But I want to send the same data on http://www.bbbbbb.com/2nd-file.php . My form is on HTML page and I want to send data via one click on Send Data only. So is this possible to send data on both PHP pages using pure JavaScript not JQuery? If yes then how?

Update:

My both PHP receiving files have codes something like below...

<?php
$data_from_site= $_POST['NAME'];
echo $data_from_site;
?>

Use an iframe as described here ,

<input type="submit" value="Send Data" onclick='javascript: return SubmitForm()' />

<iframe name='frame_result1' width='350px' height='100px' frameborder='0'></iframe>
<iframe name='frame_result2' width='350px' height='100px' frameborder='0'></iframe>

function SubmitForm()
{
    document.forms['theForm'].action='http://www.aaaaaa.com/1st-file.php';
    document.forms['theForm'].target='frame_result1';
    document.forms['theForm'].submit();

    document.forms['theForm'].action='http://www.bbbbbb.com/2nd-file.php';
    document.forms['theForm'].target='frame_result2';
    document.forms['theForm'].submit();
    return true;
}

Imho, if you don't want to use Jquery, the best solution for you is to send an xmlhttprequest via js. see Request to the Server

You can take advantage of cURL() and fputs() PHP functions. Here's the sample implementation. http://www.html-form-guide.com/php-form/php-form-submit.html

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