tokyorobot
Programmer
Hello,
I'm working on a script that submits user input from 3 different text boxes and submits this info to several different form actions.
Below is my script:
<?
if (isset($_POST["submit"]))
{
$dest = array (
""");
//form1
$hiddenvalue[0]["somevalue"] = $_POST["input1"];
//form2
$hiddenvalue[1]["somevalue"] = "1";
$hiddenvalue[1]["somevalue"] = $_POST["input2"];
//form3
$hiddenvalue[2]["somevalue"] = "5";
$hiddenvalue[2]["somevalue"] = $_POST["input3"];
$submit_to = array();
if (isset ($_POST["destination"]))
{
for ($i=0; $i<count($_POST["destination"]); $i++)
{
$submit_to[] = $dest[$_POST["destination"][$i]];
}
}
foreach ($submit_to as $i => $url)
{
$connection = curl_init($url);
$postvar = ($hiddenvalue[$i]) ? array_merge ($_POST,$hiddenvalue[$i]) : $_POST;
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $postvar);
$result = curl_exec($connection);
echo "Form No ".($i+1).":<br>";
print_r($result);
curl_close($connection);
}
Header ("Location: thank_you.html");
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="send" action="index.php" method="post">
Data1:
<input type="text" name="input1">
Data2:
<input type="text" name="input2">
Data3:
<input type="text" name="input3">
<p>
Submit form to:
<input type="checkbox" name="destination[]" value="0">
<input type="checkbox" name="destination[]" value="1">
<input type="checkbox" name="destination[]" value="2">
</p>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
For some reason, data is not submitted to some form actions. If only checkbox value="2" (the last checkbox) is selected it won't submit anything to this form action.
However, if all checkboxes are selected, the data is successfully sent to each form action.
Is there another way to do this? Perhaps another array setup?
Perhaps there's a better/easier way to submit data to multiple forms? I'm sure there is.
All help is appreciated, thanks!
I'm working on a script that submits user input from 3 different text boxes and submits this info to several different form actions.
Below is my script:
<?
if (isset($_POST["submit"]))
{
$dest = array (
""");
//form1
$hiddenvalue[0]["somevalue"] = $_POST["input1"];
//form2
$hiddenvalue[1]["somevalue"] = "1";
$hiddenvalue[1]["somevalue"] = $_POST["input2"];
//form3
$hiddenvalue[2]["somevalue"] = "5";
$hiddenvalue[2]["somevalue"] = $_POST["input3"];
$submit_to = array();
if (isset ($_POST["destination"]))
{
for ($i=0; $i<count($_POST["destination"]); $i++)
{
$submit_to[] = $dest[$_POST["destination"][$i]];
}
}
foreach ($submit_to as $i => $url)
{
$connection = curl_init($url);
$postvar = ($hiddenvalue[$i]) ? array_merge ($_POST,$hiddenvalue[$i]) : $_POST;
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $postvar);
$result = curl_exec($connection);
echo "Form No ".($i+1).":<br>";
print_r($result);
curl_close($connection);
}
Header ("Location: thank_you.html");
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="send" action="index.php" method="post">
Data1:
<input type="text" name="input1">
Data2:
<input type="text" name="input2">
Data3:
<input type="text" name="input3">
<p>
Submit form to:
<input type="checkbox" name="destination[]" value="0">
<input type="checkbox" name="destination[]" value="1">
<input type="checkbox" name="destination[]" value="2">
</p>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
For some reason, data is not submitted to some form actions. If only checkbox value="2" (the last checkbox) is selected it won't submit anything to this form action.
However, if all checkboxes are selected, the data is successfully sent to each form action.
Is there another way to do this? Perhaps another array setup?
Perhaps there's a better/easier way to submit data to multiple forms? I'm sure there is.
All help is appreciated, thanks!