Right now I am trying to figure out what is going on with the code. It doesn't make sense why it won't work. When I submit the form I get the error message "comments two" so I know where the problem is but don't understand why its happening. The $newfield variable I made seems to not be storing anything. Any help?
HTML CODE:
<div id="contact-formular">
<div id="message"></div>
<form method="post" action="contact.php" name="contactform" id="contactform">
<div class="one_half element_from_left" style="opacity: 1; left: 0px;">
<input name="name" type="text" id="name" size="30" onfocus="if(this.value == 'Name') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Name'; }" value="Name">
<input name="email" type="text" id="email" size="30" onfocus="if(this.value == 'email') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'email'; }" value="email">
<input name="phone" type="text" id="phone" size="30" onfocus="if(this.value == 'phone') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'phone'; }" value="phone">
</div>
<div class="one_half last element_from_right" style="opacity: 1; right: 0px;">
<textarea id="comments" type="text" class="top-text" name="comments" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" value="comments">Architect/ lighting designer/ property developer/ lighting enthusiast/ Will tell later</textarea>
<textarea id="newfield" type="text" class="bottom-text" name="newfield" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" value="newfield">Newfield</textarea>
</div>
<input type="submit" class="send_message" id="submit" value="SEND MESSAGE">
</form>
</div>
PHP CODE:
if (!defined("PHP_EOL")) define("PHP_EOL", "
");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$newfield = $_POST['newfield'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
} else if(trim($comments) == '') {
echo '<div class="error_message">Comments one</div>';
exit();
} else if(trim($newfield) == '') {
echo '<div class="error_message">Comments two</div>';
exit();
}
Also here is a picture of what it looks like for the error when I submit. If I remove this line of code it works but doesn't capture that area for an email:
else if(trim($newfield) == '') {
echo '<div class="error_message">Comments two</div>';
exit();
}
here is also the full php document https://codeshare.io/GAW7x5