现在我正试图找出代码发生了什么。没有理由为什么它不起作用。当我提交表单时,我收到错误消息“评论二”,所以我知道问题出在哪里,但不明白为什么会发生这种情况。我创建的$ newfield变量似乎没有存储任何内容。有什么帮助吗?
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代码:
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$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();
}
此处还有一张我提交时错误的图片。如果我删除这行代码,它可以工作但不捕获电子邮件的那个区域:
else if(trim($newfield) == '') {
echo '<div class="error_message">Comments two</div>';
exit();
}
这里也是完整的php文档https://codeshare.io/GAW7x5