1
에서 사용자가 빈 필드를 제출 한 다음 표시 방법을 잘못 입력했을 때 지금 이메일 주소 만 유효하지 않은 입력으로 표시됨 모든 필드 유효성 검사를 수정하고 싶습니다. 어떻게 도와 주실 수 있습니까?문의 양식에 유효성을 설정하는 방법
<html>
<body>
<?php
function spamcheck($field) {
// Sanitize e-mail address
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
// Validate e-mail address
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
?>
<h2>Form</h2>
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"])) {
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
From: <input type="text" name="email"><br>
Subject: <input type="text" name="subject"><br>
Message: <textarea rows="10" cols="40" name="message"></textarea><br>
<input type="submit" name="submit" value="Submit Feedback">
</form>
<?php
} else { // the user has submitted the form
// Check if the "from" input field is filled out
if (isset($_POST["email"])) {
// Check if "from" email address is valid
$mailcheck = spamcheck($_POST["email"]);
if ($mailcheck==FALSE) {
echo "Invalid input";
} else {
$email = $_POST["email"]; // sender
$subject = $_POST["subject"];
$message = $_POST["message"];
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// send mail
mail("[email protected]",$subject,$message,"From: $email\n");
echo "Thank you for sending us feedback";
}
}
}
?>
</body>
</html>