Hello, I'm creating a contact form for this website
http://www.preciousjewelslearning.org/contact.php
The Name and Email Validates but I don't know why if I leave the comment box empty, the form just goes through. I'm making the fields phone and option "Optional" This is the process.php that comes after the contact.php page. Here is the php code
<?php
function displayRequired($fieldName) {
echo " \".$fieldName\"is required.<br />n";
}
function validateInput($data, $fieldName){
global $errorCount;
if (empty($data)){
displayRequired($fieldName);
++$errorCount;
$retval = "";
} else {
$retval = trim($data);
$retval = stripslashes($retval);
}
return ($retval);
}
$Name = validateInput($_POST['name'], "First Name");
$Email = validateInput($_POST['email'], "Email");
$Phone = $_POST['phone'];
$Options = $_POST['select'];
$Comments = validateInput($_POST['comments'], "Comments");
if ($errorCount>0){
echo "Please re-enter the information below.<br />\n";
redisplayForm($Name, $Email, $Phone, $Options, $Comments);
}
else
{
$To = "atlnycdude23@gmail.com";
$Subject = "Precious Jewels";
$From = "Precious Jewels Learning";
$Message = "Name: " . $Name. "Email " . $Email. "Phone" . $Phone. "Options" . $Options. "Comments" . $Comments;
$Headers = "From: ". $from . "<" . $to. ">\r\n";
$Headers .= "Reply-To: " . $email_text . "\r\n";
$Headers .= "Return-path: ". $email_text;
$result = mail($To, $Subject, $Message, $Headers);
if ($result)
$resultMsg = "You message was sucessfully sent.";
else
$resultMsg = "There was a problem sending your message.";
}
?>
<h2 style="text-align:center">Thank You!</h2> <!--To Display after submitting or error handling-->
<p style="line-height:200%">Thank you for contacting us<?php
if (!empty($fieldName))
echo " , $fieldName"?>. <?php echo $resultMsg;?>
<?php
function redisplayForm($Name, $Email, $Phone, $Options, $Comments){
?>
<form action="process.php" method="post">
<fieldset class="first">
<label class="labelone" for="name">Name:</label><!--css rule-->
<input type="text" name="name" <?php echo $Name; ?> />
<label for ="email">Email:</label>
<input type="text" name="email" <?php echo $Email; ?> />
<label for="phone">Phone:</label>
<input type="text" name="phone" <?php echo $Phone; ?> />
<label for="select">Choose from the list:</label>
<select name="select" id="select">
<option>Select from the list....</option>
<option value="preschool">Preschool</option>
<option value="child">Child Care</option>
<option value="health">Health and Nutrition</option>
<option value="camp">Summer Day Camp</option>
<option value="empowerment">Teen Empowerment</option>
<option value="club">Teen Club</option>
<option value="group">Parent Resource Support Group</option>
<option value="request">Other Special Requests</option>
</select>
<label for="comments">Comments:</label>
<textarea type="text" name="comments" <?php echo $Comments; ?>> </textarea>
</fieldset>
<fieldset>
<input class="btn" name="submit" type="submit" value="Send Email"/>
<input class="btn" name="reset" type="reset" value="Clear Form" />
</fieldset>
</form>
<?php
}
?>
Please help, thanks in advanced!