I am doing a php contact form with validation for this website.
http://www.preciousjewelslearning.org/contact.php
The form "works" and the form validates the way it should work but also here is what I've accomplished. Once the form validates, the user will receive a thank you message once the information has been sent to me by email on the same process.php page. if the user did not filled the form completely then the process.php page will then display with the form partially filled out since I've made the form "sticky" so they can have another chance to fill out the required fields. My concern is is, on that particular page, why the "Thank you" message is displayed on the bottom without hitting the submit button? It should not be there. Her
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");
$Comments = validateInput($_POST['comments'], "Comments");
$Phone = $_POST['phone'];
$Options = $_POST['select'];
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" value="<?php echo $Name; ?>" />
<label for ="email">Email:</label>
<input type="text" name="email" value="<?php echo $Email; ?>" />
<label for="phone">Phone:</label>
<input type="text" name="phone" value="<?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 name="comments"><?php echo $Comments;?></textarea>
</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
}
?>
I think the issue lies in this line of syntax but i'm not very sure....
?>
<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){
?>
Much appreciated for your help in advanced 🙂