Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Form Script

Status
Not open for further replies.

tokyorobot

Programmer
Jan 30, 2006
1
US
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've only looked at this briefly so apologies if this is a wild goose chase.

the majority of the code looks fine so i think the problem is in the foreach loop only. it looks to me as though you are inferring the value of $hiddendata from the key of the submit_to array. but if only the last checkbox is checked the $submit_to array will only have one element and this will be at element 0. the corresponding hiddendata element will be the text box relating to the first text field and not the third, which it appears that you actually want.

hth
Justin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top