on my web site contact form:
http://www.inspired-evolution.com/Contact.php
I am still having a few problems with the return results after filling out the form. Basically I am wanted to return an error msg. when all of the required fields are not filled out (those with a red *), and an invalid email address will also return an error.
Right now even if you don't fill out the required fields, you still get my thank-you message for filling out the form correctly (as well as getting the error msg.). If someone has a chance try out the form yourself and you will see what I mean.
anyway, the validation code I currently have is:
Code: Select all
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$URL = $_POST['URL'];
$Contact_Preference = $_POST['Contact_Preference'];
$Contact_Time = $_POST['Contact_Time'];
$message = $_POST['Message'];
if ((!$firstname) || (!$Contact_Preference)) {
echo'<p><strong>Error!</strong> Fields marked <span class="red"> *</span> are required to continue.</p><br />';
}
if (!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email)) {
echo '<p>Invalid email address entered. Please <a href="Contact.php" title="Contact Me">Try again.</a></p><br />';
}
$email_address = "webguync@gmail.com";
$subject = "There has been a disturbance in the force";
$message = "Request from: $firstname $lastname\n\n
Company name: $company\n
Phone Number: $phone\n
Email Address: $email\n
URL: $URL\n
Please Contact me via: $Contact_Preference\n
The best time to reach me is: $Contact_Time\n
I wish to request the following additional information: $Textarea";
mail($email_address, $subject, $message, "From: $email \nX-Mailer: PHP/" . phpversion());
echo "<p>Hello, <strong>$firstname</strong>.<br /><br />
We have received your request for additional information, and will respond shortly.<br />
Thanks for visiting inspired-evolution.com and have a wonderful day!<br /><br />
Regards,<br /><br />
<strong>Inspired Evolution</strong></p>";
?>