I have a contact-form with text-areas for name, e-mail and the message.
The only area i want required for validation is the area for e-mail.
When validation for e-mail is accepted, i want to show a message showing the content of the name-area and a pop-up that message is sent.
How do i write php that echoes the name-area without validation ?
Here is the code with validation for both name- and e-mail - i want to keep validation for e-mail and clear validation for name but still echo name when passed ?
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//THIS PART SHOULD NOT validate but just echo if no error in e-mail
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '#@gmail.com'; //Put your own email address here
$body = "Email: $email \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>