Forum Moderators: coopster
This is how I am picturing it in my head, but the problem is if the action of the form is set to post to itself for validation, how can it then automatically post to the gateway url given there are no errors?
<form id="order" method="post" action="form.php">
<p><label>First Name</label><input type="text" name="firstname" class="text-input" id="firstname" value="<? echo $firstname?>"/></p>
<p><label>Last Name</label><input type="text" name="lastname" class="text-input" id="lastname" value="<? echo $lastname?>"/></p>
<input type="image" src="mybtn.png" class="order-submit" name="submit" value="Submit Order"/>
</form>
<?
//code to put post info into variables and validate
?>
<?
//set return url
$ReturnURL = 'https://www.example.com/response.php';
//create post string
$fields = array(
'CustomerFirstName'=>urlencode($firstname),
'CustomerLastName'=>urlencode($lastname),
'ReturnURL'=>urlencode($ReturnURL),
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//send it to gateway
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.examplegateway.com/process.asp");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$Response = trim(curl_exec($ch));
echo $Response;
curl_close ($ch);
?> <?
echo $_GET["firstname"];
echo $_GET["lastname"];
?>
$Response = trim(curl_exec($ch));
echo $Response;
if ([some input from the form]) {
// validate
if ([validate error]) {
output form here with error
}
else {
if ($Response = trim(curl_exec($ch))) {
// output your localized response here
}
else {
// There should be some form error to display here.
// Or possibly an error from the gateway.
}
}
}
else {
// output the form here
}