エニオンはこれを手伝ってもらえますか?
私はphpを初めて使用し、簡単な連絡フォームの検証ルールを開発しようとしています。
フォームの他の部分が検証に失敗したときにselectfieldsのリセットを停止するにはどうすればよいですか?
コードは以下のとおりです。
<?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.
{
?>