ok guys is there any way to submit a form to a number of pages at the same time?

can we provide a number of urls instead of just one action attribute?

one form send the same info to different pages. i mean something like an email, but it is not an email. there will be a number of identical scripts which will be called at teh same time in the <form> tag.

ive thought on this, but can figure out a way for this.

Dani AI

Generated

HTML forms only allow a single action URL. As demonstrated, posting to one PHP endpoint and then includeing other scripts is a simple, valid solution: included files run in the same PHP process and share $_POST, so the form data is immediately available to them. That approach is fine when the other scripts live on the same server and are safe to execute in-process.

Important caveats: include does not perform separate HTTP requests. Included code runs with the current request's context (same globals, no separate headers) and including remote URLs is usually disabled and insecure. If the goal is to actually deliver the same HTTP POST to other web services (different hosts or separate processes), perform server-side HTTP calls instead. For parallel outbound POSTs, curl_multi is efficient and non-blocking compared to sequential requests:

$targets = ['https://a.example/endpoint', 'https://b.example/endpoint'];
$mh = curl_multi_init();
$handles = [];

foreach ($targets as $url) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_multi_add_handle($mh, $ch);
  $handles[] = $ch;
}

$running = null;
do {
  curl_multi_exec($mh, $running);
  curl_multi_select($mh);
} while ($running > 0);

foreach ($handles as $ch) {
  $resp = curl_multi_getcontent($ch);
  $err  = curl_error($ch);
  curl_multi_remove_handle($mh, $ch);
  curl_close($ch);
}

curl_multi_close($mh);

Other options: send multiple client-side fetch/XHR requests (watch CORS), or enqueue the payload (Redis/RabbitMQ/queue worker) and let background jobs deliver to many endpoints reliably. Always handle partial failures, retries, idempotency, timeouts and logging when distributing a single form to multiple receivers.

References: MDN form element (MDN), PHP include (php.net), PHP curl_multi_exec (php.net).

Recommended Answers

All 2 Replies

When you post your form to a page, include other php files and process the posted data.
ie.,
page1.php submits to page2.php .
in page2.php, include page3.php and page4.php. So, When you post the form data to page2.php , the same values will be accessible in page3.php and page4.php . Here is an example.

//testpost1.php
<html>
<body>
<form method="post" action="testpost2.php">
Name: <input type="text" name="name">
<br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
<?php
//this is testpost2.php
include "testpost3.php";
print_r($_POST);
?>
<?php
//this is testpost3.php
print_r($_POST);
?>

It will print the form data twice!

it worked thanx.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.