I have a contact.php page on my website which isn't giving me the correct output I wanted. Please see pics:
What I wanted to happen after I hit submit is the thanks.html page to open. Instead it displays the contact.php page with a thanks message.
Can anybody point out how to alter the php script to make the error and thanks pages to display when req'd.
Thanks.
<div id="main">
<div id="content">
<h2 class="touch">Get In Touch</h2>
<p>All fields required.</p>
<?php
//really thorough email address validation function
function isValidEmail($email) {
// First, we check that there's one @ symbol,
// and that the lengths are right.
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters
// in one section or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if
(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
$local_array[$i])) {
return false;
}
}
// Check if domain is IP. If not,
// it should be valid domain name
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if
(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$",
$domain_array[$i])) {
return false;
}
}
}
return true;
}
//variables to hold the form status
$showform = true;
$formdata = array(
);
//process the form if submitted
if(isset($_POST['Submit'])) {
//grab the values from the form
$name = trim(stripslashes($_POST['Name']));
$email = trim(stripslashes($_POST['Email']));
$comments = trim(stripslashes($_POST['Comments']));
//email variables
$to = "huw@huwrowlands.co.uk";
$subject = "Huw Rowlands Website Contact Form";
$headers = "From: $email\n";
// Gather all data for email body.
$body = "";
$body .= "Name: ";
$body .= $name;
$body .= "\n\n";
$body .= "Email: ";
$body .= $email;
$body .= "\n\n";
$body .= "Comments: ";
$body .= $comments;
$body .= "\n\n";
//perform some validation
$errors = array();
if(empty($name)) {
$errors['name'] = "Enter your name";
}
if(empty($email)) {
$errors['email'] = "Enter your email";
}
elseif(!isValidEmail($email)) {
$errors['email'] = "Email address invalid";
}
if(empty($comments)) {
$errors['comments'] = "Enter a message";
}
//if the form is valid then send the message
if(count($errors)==0) {
if(mail($to,$subject,$body,$headers)) {
//hide the form, show success message instead
$showform = false;
}
else {
$errors['form'] = "Unable to send message, try again";
}
}
}
//show the form if needed
if($showform) {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="webform" onsubmit=" return checkForm()">
<fieldset>
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" class="inputbox"<?php echo isset($name)?' value="'.$name.'" ':''; ?>/>
<div class="error<?php echo isset($errors['name'])?' error2':''; ?>" id="nameError">Name Required!</div>
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" class="inputbox" <?php echo isset($email)?' value="'.$email.'" ':''; ?>/>
<div class="error<?php echo isset($errors['email'])?' error2':''; ?>" id="emailError">Valid Email Required!</div>
<label for="Comments">Comments:</label>
<textarea name="Comments" rows="" cols="" id="Comments"><?php echo isset($comments)?$comments:''; ?></textarea>
<div class="error<?php echo isset($errors['comments'])?' error2':''; ?>" id="commentsError"><br />Comments Required!</div>
<input type="submit" value="Submit" name="Submit" class="submit"/>
</fieldset>
</form>
<?php
} else { //otherwise show the successpage
?>
<h2 class="thanks">Thanks!</h2>
<p>Your message was sent.</p>
<?php } ?>
Help




















