任何人都可以帮忙吗?
我是 php 新手,正在尝试为简单的联系表单开发验证规则。
当表单的其他部分验证失败时,如何停止选择字段重置?
代码如下:
<?php
$error = '';
$title = '';
$firstname = '';
$surname = '';
$email = '';
$phone = '';
$comments = '';
$how = '';
$verify = '';
if(isset($_POST['contactus'])) {
$title = $_POST['title'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$how = $_POST['how'];
$verify = $_POST['verify'];
ini_set("sendmail_from", $email_from, "enquiries@blah.com");
// Errors
if(trim($title) == '') {
$error = '<div class="error_message">Please enter your Title.</div>';
}
else if(trim($firstname) == '') {
$error = '<div class="error_message">Please enter your First name.</div>';
}
else if(trim($surname) == '') {
$error = '<div class="error_message">Please enter your Surname.</div>';
}
else if(!validEmail($email)){
$error = '<div class="error_message">Please enter a valid email address.</div>';
$email = '';
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "enquiries@blah.com";
$e_subject = 'Care at Home Enquiry from ' . $title . $surname . '.';
$e_body = "You have been contacted by $name with regards to an Advantage Nurses general enquiry, contact details and message are as follows.\r\n\n";
$e_content = "Title: " . $title .
"\r\n\nFirst name:" . $firstname .
"\r\n\nSurname: " . $surname .
"\r\n\nEmail: " . $email .
"\r\n\nPhone: " . $phone .
"\r\n\nEnquiry: " . $comments .
"\r\n\nHow Did You Hear About Us: " . $how;
//$e_reply = "\r\n\nYou can contact $name via email, $email or via phone $phone";
$msg = $body . $e_content . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
{
// Email has sent successfully, echo a success page.
echo "<div id='succsess_page'>";
echo "<h1>Enquiry Submitted.</h1>";
echo "<p>Thank you <strong>$title $surname</strong>, your enquiry has been submitted to us.<br /><br /> A member of our Team will contact you within 48 hours.</p>";
echo "</div>";
} else echo "Error. Mail not sent";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>