I have a payment form that submits to itself like this…
<!-- HTML PAYMENT FORM -->
<form id="payment" action="" method="post">
The idea is that the first time the page is displayed, the Form has not been submitted, so it skips my data-validation PHP and displays the HTML.
Then when a user submits the form, there is $_POST data, so my PHP takes over and validates it.
If the Form Data has errors, the form is re-displayed with error messages.
If the Form Data is okay, then more PHP submits it to the payment gateway.
This self-referencing page works fine on my laptop, but when I post it to my web hosting account and submit the Form with valid data, all I get is a blank page?!
I am thinking that I need to use different syntax to get the form to refer to itself…
Again, when I run my code locally, it works and I even get a response back from the payment gateway since they send a response back immediately via POST.
Here is a stripped down version of my page…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href=".css">
<style type="text/css" >
someStyleHere{
font-weight: bold;
}
</style>
</head>
<body>
<?php
// Check Form.
if (isset($_POST['submitted'])){
// Handle Form.
// Trim all incoming data.
$trimmed = array_map('trim', $_POST);
// CHECK BILLING INFORMATION.
// Check First Name.
if (!empty($_POST['firstName'])){
if (preg_match('/^[A-Z \\'.-]{2,20}$/i', $_POST['firstName'])){
$firstName = $_POST['firstName'];
}else{
$errors['firstName'] = 'Must be 2-20 characters (A-Z \\' . -)';
}
}else{
$errors['firstName'] = 'Please enter your First Name.';
}
// Determine if any errors.
if (empty($errors)){
// PROCESS PAYMENT.
// Output the Response Array to the screen as an HTML Numbered List.
echo "<OL>\
";
foreach($response_array as $value){
echo "<LI>" . $value . " </LI>\
";
}
echo "</OL>\
";
// Printe Response Code.
switch($response_array[0]){
case "1":
echo "Response Code: Approved";
break;
case "2":
echo "Response Code: Declined";
break;
}
// Do not re-display Payment Form!!!
exit();
// *********************************************************************
}// End of PROCESS PAYMENT.
}// End of HANDLE FORM.
?>
<!-- HTML PAYMENT FORM -->
<form id="payment" action="" method="post">
<fieldset>
<legend>Billing Details</legend>
<ol>
<!-- First Name -->
<li>
<label for="firstName">First Name:</label>
<input id="firstName" name="firstName" class="text" type="text"
maxlength="20" value="<?php echo $firstName; ?>" />
<?php
if (!empty($errors['firstName'])){
echo '<span class="error">' . $errors['firstName'] . '</span>';
}
?>
</li>
</ol>
</fieldset>
<!-- Submit Form -->
<fieldset id="submit">
<input name="submit" type="submit" value="Place Order" />
<input name="submitted" type="hidden" value="true" />
</fieldset>
</form>
</body>
</html>
If I run that code online, I keep getting back a white screen?!
And when I do View Source, I see this…
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href=".css">
<style type="text/css" >
</style>
</head>
<body>
So something is getting gobbled up on the server?! :-/
That’s what you would get when $_POST[‘submitted’] exists and everything is valid so presumably you haven’t gone back far enough with your browser and still have the post variables being read by the page. Try closing and reopening the browser.
Do not use “$_POST[‘submitted’]” to check if the form has been sumbitted, instead use a required field. Not all browsers will send the submit button’s value. Second, when troubleshooting use “var_dump” just before all your code.