我是 PHP 新手,所以请耐心等待这个相当简单的问题。
我有一个这样的 PHP 表单设置 >>
<?php
if($_POST){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$comments = $_POST['comments'];
if($comments)
$error = "There was an error, please give us a call at ### ###-####.";
else{
if($name=="Name" || $email=="Email" || $message=="Message"){
$error = "All fields are required, please fill them out and try again.";
}else
$header = "From: $name <$email>";
$message = "Name: $name\n\nEmail: $email\n\nMessage: $message";
if(mail("email@domain.com", 'Form Submission', $message, $header))
$success = "Thanks for sending us your message, we'll get back to you shortly.";
else
$error = "There was an error, please give us a call at ### ###-####.";
}
if($error)
echo '<div class="msg error">'.$error.'</div>';
elseif($success)
echo '<div class="msg success">'.$success.'</div>';
}
?>
基本思想是表单在每个字段中都预先填写了描述性文本,但是当您单击它们时,它们会通过 Javascript 清除。我想防止人们在不填写表格的情况下按发送,因此 "if($name=="Name" || $email=="Email" || $message=="Message"){" 位. 但是,虽然该消息正在工作,但表单仍在提交。为什么是这样。另请注意,“评论”字段实际上是一个蜜罐。谢谢!