domdeez Posted January 17, 2007 Share Posted January 17, 2007 Hello,I post (via web form) to a php script to process credit cards (AIM Method/Authorize.net). On successfull transactions the script sends the form data to an admin email address (it also sends a confirmation email to the customer). On seperate occasions I also post (via web form) to another program called Form Tools. Using a database Form Tools collects and formats the form data. FYI: I send form data to Form Tools via <form action="process.php" method="post"><input type="hidden" name="form_tools_form_id" value="1" />Is there a way to change the behavior of the script below so that instead of emailing the form data after success, it sends the data to Form Tools? Or is there a way to set up say a script such as handler.php - where the script below posts to that and then handler.php posts to form tools with the appropriate "form" and "input" data given above?Any help would be appreciated...Aside from the set variables portion of the script, here is the entire working script.[sup]$post_array = array( "x_login" => $username ,"x_tran_key" => $transaction_key ,"x_version" => "3.1" ,"x_test_request" => $x_test_request ,"x_delim_data" => "TRUE" ,"x_relay_response" => "FALSE" ,"x_first_name" => $_REQUEST['first_name'] ,"x_description" => $_REQUEST['description'] ,"x_last_name" => $_REQUEST['last_name'] ,"x_address" => $_REQUEST['address'] ,"x_city" => $_REQUEST['city'] ,"x_state" => $_REQUEST['state'] ,"x_zip" => $_REQUEST['zip_code'] ,"x_phone" => $_REQUEST['phone'] ,"x_email" => $_REQUEST['email'] ,"x_country" => "USA" ,"x_email_customer" => "FALSE" ,"x_amount" => $total_cost ,"x_method" => "CC" ,"x_type" => "AUTH_CAPTURE" ,"x_card_num" => $credit_card_number ,"x_exp_date" => $credit_card_expiration_date ); // [3] Convert Array to POST string (key_1=val_1&key_2=val_2...) reset($post_array); while (list ($key, $val) = each($post_array)) { $data .= $key . "=" . urlencode($val) . "&"; } // [4] Securely POST to AuthorizeNet using "curl"$ch = curl_init("https://secure.authorize.net/gateway/transact.dll"); // URL of gateway for cURL to post tocurl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from responsecurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // use HTTP POST to send form data### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###$resp = curl_exec($ch); //execute post and get resultscurl_close ($ch); // [5] Handle Response FROM AuthorizeNet // Set $authorized = TRUE if transaction wass successful if ($resp{0} == 1) { $header_1 = "Return-Path: $from_email\n"; $header_1 .= "X-Sender: $from_email\n"; $header_1 .= "From: $from_email <$from_email>\n"; $header_1 .= "X-Mailer:PHP 5.1\n"; $header_1 .= "MIME-Version: 1.0\n"; $header_1 .= "Content-Type: text/html; charset=utf-8\r\n"; $subject_1 = "Details"; $message_1 .= "<html>"; $message_1 .= "<body>"; $message_1 .= "<p><font size=\"2\" face=\"Verdana\">Message to cutomer.<p>Gift Amount:\${$_REQUEST['total_cart']}</font></p>"; $message_1 .= "</body>"; $message_1 .= "</html>"; mail($_REQUEST['email'],$subject_1,$message_1,$header_1); $header = "Return-Path: $admin_email\n"; $header .= "X-Sender: $admin_email\n"; $header .= "From: Name of Company<$from_email>\n"; $header .= "X-Mailer:PHP 5.1\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: text/html; charset=utf-8\r\n"; $subject = "Email Subject"; $message .= "<html>";$message .= "<body>";$_POST['credit_card_number'] = false;mail($b1email,$subject,$message,$header); foreach($_POST as $key => $value){ $message .= "$key : $value<br>"; } $message .= "</body>"; $message .= "</html>";foreach($admin_email as $key => $value){ mail($value,$subject,$message,$header); } header("location: $trans_accepted"); }elseif($resp{0} == 2){ header("location: $trans_failed"); }elseif($resp{0} == 3){echo <<<END_HTML<p style="margin-top: 0; margin-bottom: 0" align="center"><b><font face="Arial" size="2">There was an error processing your request.</font></b></p><p align="center"><font face="Arial"><textarea rows="5" name="S1" cols="41" style="font-weight: 700">{$resp}</textarea></font></p>END_HTML; } ?>[/sup] Link to comment https://forums.phpfreaks.com/topic/34604-php-form-handling/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.