FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to achieve 2 actions on html form "submit"





xenonius
I have in my site a form which is sent to another domain's web page.
The action is defined as: action="htpps://xxxxxxx.com/pagename".

I need to modify this as follows:
When 'submit' is pressed, I want to have 2 actions:
1. Send the form data to the same predefined web page.
2. Email the form data to my email address.


I tried curl php code as shown below:

$ch = curl_init("htpps://xxxxxxx.com/pagename");
$params = '';
// include POST variables.
foreach($_POST as $name => $value) {
$params .= urlencode($name).'='.urlencode($value).'&';
}
// chop off last ampersand
$params = substr($params, 0, strlen($params)-1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$response = curl_exec($ch);
curl_close($ch);

To my agony, the data was not sent to htpps://xxxxxxx.com/pagename.


I then tried http_post function, a php code as shown below, and this, too, did not work.

function HTTP_Post($URL,$data, $referrer="") {

// parsing the given URL
$URL_Info=parse_url($URL);

// Building referrer
if($referrer=="") // if not given use this script as referrer
$referrer=$_SERVER["REQUEST_URI"];

// making string from $data
foreach($data as $key=>$value)
$values[]="$key=".urlencode($value);
$data_string=implode("&",$values);

// Find out which port is needed - if not given use standard (=80)
if(!isset($URL_Info["port"]))
$URL_Info["port"]=80;
$request = "";
// building POST-request:
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
$result = "";
$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);
fputs($fp, $request);
while(!feof($fp)) {
$result .= fgets($fp, 128);
}
fclose($fp);

return $result;
}


Any suggestions?

Thanks all,
Xenonius
Related topics
Can someone make me a php script?
form submit
HTML form, list of options or text input
Send Mail HTML Form
How to upload a file via html-form and php?
Php form.
anyone know of a good php form processer script
Assign unique rank in html form using javascript possibly?
Error trying to display SQL statement in html table
Html Forms help please?
100frih$ to anyone who fixes this HTML form
Help needed with getting table to auto update via html form
upload file to server using html form and CGI C
what are after dot function for?
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.