I have a form on a free standing contact form, however when I attempt to use it at the bottom of a scrolling page or in a section with an anchor it won't visually validate. In other words the error messages won't appear. The form will send an email if all the required fields are filled.But visually nothing happens!? http://patrickmchugh.com/test/
To see how it should work, please see a free standing contact.php patrickmchugh.com/test/contact.php This is how the error messages should work.
<?php
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST['save']) || $_POST['save'] != 'contact') {
header('Location: index.php#content'); exit;
}
// get the posted data
$name = $_POST['contact_name'];
$email_address = $_POST['contact_email'];
$subject = $_POST['contact_subject'];
$message = $_POST['contact_message'];
// check that a name was entered
if (empty($name))
$error = 'You must enter your name.';
// check that an email address was entered
elseif (empty($email_address))
$error = 'You must enter your email address.';
// check for a valid email address
elseif (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email_address))
$error = 'You must enter a valid email address.';
// check that a message was entered
elseif (empty($message))
$error = 'You must enter a message.';
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
header('Location: index.php?e='.urlencode($error).'#content2'); exit;
}
// write the email content
$email_content = "Name: $name
";
$email_content .= "Email Address: $email_address
";
$email_content .= "Subject: $subject
";
$email_content .= "Message:
$message";
// send the email
mail ("patrick@patrickmchugh.com", "Enquiry from Connolly O'Neill Website", $email_content);
// send the user back to the form
header('Location: index.php?s='.urlencode('Thank you for your message.').'#contact2'); exit;
?>