Hi, I was wondering if someone might be able to point me in the right direction.
I've got 4 files I'm working with:
contact.php
contproc.php
missing.php
thanks.php
When a user goes to the contact.php and completes the form and submits it, having filled in all the fields, he/she is redirected to the thanks.php page as I want.
However, when the form is submitted with required field information missing the user is redirected to a completely blank missing.php page!
The original code in the contproc.php file that did successfully generate the error information I'm looking to redirect was:
if($error_msg != ""){
echo "You didn't fill in these required fields:<br>"
.nl2br($error_msg) .'<br>Please <a href="javascript:history.back()">return</a> to the previous page and try again.';
exit;
The resulting error page appears unstyled and shows nothing relating to the original website but does provide a working link back to the form before it was submitted.
If I remove the php error display code from the missing.php the browser displays the missing.php correctly albeit with the error information missing.
Any help with this would be much appreciated.
My current code for the contproc.php and missing.php files is as follows:
contproc.php
<?
// This is the beginning of the PHP code
session_start();
$surname = $_POST['surname'];
$forename = $_POST['forename'];
$title = $_POST['title'];
$postcode = $_POST['postcode'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$arrival = $_POST['arrival'];
$depart = $_POST['depart'];
$single = $_POST['single'];
$double = $_POST['double'];
$smoking = $_POST['smoking'];
$comments = $_POST['comments'];
$error_msg = "";
$msg = "";
if(!$surname){
$error_msg .= "Your surname \n";
}
if($surname){
$msg .= "Surname: \t $surname \n";
}
if(!$forename){
$error_msg .= "Your first name \n";
}
if($forename){
$msg .= "First Name: \t $forename \n";
}
if($title){
$msg .= "Title: \t $title \n";
}
if(!$postcode){
$error_msg .= "Your postcode \n";
}
if($postcode){
$msg .= "Postcode: \t $postcode \n";
}
if(!$country){
$error_msg .= "Your country \n";
}
if($country){
$msg .= "Country: \t $country \n";
}
if(!$phone){
$error_msg .= "Your phone \n";
}
if($phone){
$msg .= "Phone: \t $phone \n";
}
if(!$email){
$error_msg .= "Your email \n";
}
if($email){
if(!eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\._\-]+\.[a-zA-Z]{2,4}", $email)){
echo "\n<br>That is not a valid email address. Please <a href=\"javascript:history.back()\">return</a> to the previous page and try again.\n<br>";
exit;
}
$msg .= "Email: \t $email \n";
}
if($arrival){
$msg .= "Arrival Date: \t $arrival \n";
}
if($depart){
$msg .= "Departure Date: \t $depart \n";
}
if($single){
$msg .= "Single: \t $single \n";
}
if($double){
$msg .= "Double: \t $double \n";
}
if($smoking){
$msg .= "Smoking: \t $smoking \n";
}
if($comments){
$msg .= "Comments: \t $comments \n";
}
$sender_email="";
if(!isset($name)){
if($name == ""){
$sender_name="Web Customer";
}
}else{
$sender_name=$name;
}
if(!isset($email)){
if($email == ""){
$sender_email="Customer@website.com";
}
}else{
$sender_email=$email;
}
if($error_msg != ""){
$_SESSION['error_msg'] = $error_msg;
header("Location: ../missing.php"); /* Redirect browser */
exit();
}
$mailheaders = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: $sender_name <$sender_email>\r\n";
$mailheaders .= "Reply-To: $sender_email <$sender_email>\r\n";
mail("reception@thegrovehousehotel.co.uk","Grove House Website Enquiry",stripslashes($msg), $mailheaders);
header("Location: http://www.thegrovehousehotel.co.uk/thanks.php"); /* Redirect browser */
//This is the end of the PHP code
?>
missing.php
<?php
session_start();
include "header.php";
?>
<table width="100%" border="0">
<tr><td align="center" valign="top"><table width="600" valign="top" border="0" cellpadding="5"><tr>
<td width="110" valign="top" ><?php include "navbar.php"; ?></td>
<td width="461" rowspan="2" valign="top"><h1 class="h1-main">Missing Form Information</h1>
<p align="left">You didn't fill in these required fields:</p>
<?php
// If the error session variable is set, a message is to be displayed.
if (isset($_SESSION['error_msg'])) {
// Display it.
echo "<p align="left">{$_SESSION['error_msg']}</p>";
// And forget it.
unset($_SESSION['error_msg']);
}
?>
<p align="left">Please <a href="javascript:history.back()">return</a> to the previous page and try again.</p>
<p align="left"> </p>
<p align="center"> </p>
<hr><p> </p></td></tr></table></td></tr></table>
<?php include "footer.php"; ?>