![]() |
|
Multiple Action Form - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: PHP (https://sinister.li/Forum-PHP) +--- Thread: Multiple Action Form (/Thread-Multiple-Action-Form) |
Multiple Action Form - hubba - 03-25-2013 Hi. Is there a PHP code, which submits my form to multiple PHPs ? Form looks like this. <formg name="myWebForm" action="multiple.php" method="post"> <input type="text" />...<br /> <input type="submit" value="SUBMIT" /> </form> And I want the PHP script multiple.php to post my form data to PHPs action1.php and action2.php . Any ideas or alternatives? Thank You. Multiple Action Form - hubba - 03-25-2013 Hi. Is there a PHP code, which submits my form to multiple PHPs ? Form looks like this. <formg name="myWebForm" action="multiple.php" method="post"> <input type="text" />...<br /> <input type="submit" value="SUBMIT" /> </form> And I want the PHP script multiple.php to post my form data to PHPs action1.php and action2.php . Any ideas or alternatives? Thank You. RE: Multiple Action Form - The Alchemist - 03-25-2013 Try and learn PHP cURL. I'm showing you a sample script. Suppose your original form is like this : Code: <form name="myWebForm" action="multiple.php" method="post">
<input name="sometext" type="text" />
<input name="pass" type="password" />
<input type="submit" value="SUBMIT" />
</form>It has two fields, which are textboxes named sometext and pass, your multiple.php has to be like this : PHP Code: <?php
if(isset($_POST['sometext'],$_POST['pass']))
{
for($i=1;$i<=2;$i++)
{
$ch = curl_init("http://url.of/action".$i.".php");
curl_setopt($ch, CURLOPT_POST, true); // We'll post data
curl_setopt($ch, CURLOPT_POSTFIELDS, "sometext=".$_POST['sometext']."&pass=".$_POST['pass']); // Two post fields added
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($execute = curl_exec($ch))
{
echo "Done in action".$i.".php<br />";
}
curl_close($ch);
}
}
?>RE: Multiple Action Form - The Alchemist - 03-25-2013 Try and learn PHP cURL. I'm showing you a sample script. Suppose your original form is like this : Code: <form name="myWebForm" action="multiple.php" method="post">
<input name="sometext" type="text" />
<input name="pass" type="password" />
<input type="submit" value="SUBMIT" />
</form>It has two fields, which are textboxes named sometext and pass, your multiple.php has to be like this : PHP Code: <?php
if(isset($_POST['sometext'],$_POST['pass']))
{
for($i=1;$i<=2;$i++)
{
$ch = curl_init("http://url.of/action".$i.".php");
curl_setopt($ch, CURLOPT_POST, true); // We'll post data
curl_setopt($ch, CURLOPT_POSTFIELDS, "sometext=".$_POST['sometext']."&pass=".$_POST['pass']); // Two post fields added
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($execute = curl_exec($ch))
{
echo "Done in action".$i.".php<br />";
}
curl_close($ch);
}
}
?>RE: Multiple Action Form - 1llusion - 03-29-2013 (03-25-2013, 12:00 PM)The Alchemist Wrote: Just a little thing that I like to use. Using "isset" is nice, but doesn't really help you a lot. If a paramater is set, it doesn't mean that it has a value. A URL of: Code: www.example.com/index.php?paramI prefer to use the function Code: empty()Code: www.example.com/index.php?param=0To accept 0 as a value, you need to do something like: PHP Code: function is_blank($value) {
return empty($value) && !is_numeric($value);
}
I'm posting this, because your curl calls could submit empty values which could cause a chain reaction of errors. RE: Multiple Action Form - 1llusion - 03-29-2013 (03-25-2013, 12:00 PM)The Alchemist Wrote: Just a little thing that I like to use. Using "isset" is nice, but doesn't really help you a lot. If a paramater is set, it doesn't mean that it has a value. A URL of: Code: www.example.com/index.php?paramI prefer to use the function Code: empty()Code: www.example.com/index.php?param=0To accept 0 as a value, you need to do something like: PHP Code: function is_blank($value) {
return empty($value) && !is_numeric($value);
}
I'm posting this, because your curl calls could submit empty values which could cause a chain reaction of errors. RE: Multiple Action Form - The Alchemist - 03-29-2013 (03-29-2013, 02:53 AM)1llusion Wrote: All right. I'll be using empty() from next time. Ofcourse I'll make a separate function that check for multiple parameters and also check for that 0 condition. So, the PHP would be like this for non-numeric values : PHP Code: <?php
if(!empty($_POST['sometext']) && !empty($_POST['pass']))
{
for($i=1;$i<=2;$i++)
{
$ch = curl_init("http://url.of/action".$i.".php");
curl_setopt($ch, CURLOPT_POST, true); // We'll post data
curl_setopt($ch, CURLOPT_POSTFIELDS, "sometext=".$_POST['sometext']."&pass=".$_POST['pass']); // Two post fields added
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($execute = curl_exec($ch))
{
echo "Done in action".$i.".php<br />";
}
curl_close($ch);
}
}
?>RE: Multiple Action Form - The Alchemist - 03-29-2013 (03-29-2013, 02:53 AM)1llusion Wrote: All right. I'll be using empty() from next time. Ofcourse I'll make a separate function that check for multiple parameters and also check for that 0 condition. So, the PHP would be like this for non-numeric values : PHP Code: <?php
if(!empty($_POST['sometext']) && !empty($_POST['pass']))
{
for($i=1;$i<=2;$i++)
{
$ch = curl_init("http://url.of/action".$i.".php");
curl_setopt($ch, CURLOPT_POST, true); // We'll post data
curl_setopt($ch, CURLOPT_POSTFIELDS, "sometext=".$_POST['sometext']."&pass=".$_POST['pass']); // Two post fields added
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if($execute = curl_exec($ch))
{
echo "Done in action".$i.".php<br />";
}
curl_close($ch);
}
}
?> |