У меня есть простая форма электронной почты я отредактирован для моих потребностей, и все работает хорошо ..... кроме ....запретить слово в строке
формы имеет слово уже присутствующее в тексте поля, так что пользователь знает, что тип ..
эти слова
Имя Адрес Почтовый индекс Телефон Сообщение
если пользователь т чтобы отправить «пустую электронную почту» .... форма регистрирует ее из-за проверки электронной почты и проверки телефона (электронная почта требует @ +. и телефон требует цифр и пробелов только!)
, что я пытаюсь сделать, это запретить слова «Имя» «Адрес» «почтовый индекс» и «телефон» .....
сообщения не имеет значения меня!
вот сценарий я использую:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "My Email";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['address1']) ||
!isset($_POST['postcode']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$address1 = $_POST['address1']; // required
$postcode = $_POST['postcode']; // required
$phone = $_POST['phone']; // required
$message = $_POST['message']; // not required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$address_exp = "/^[A-Za-z 0-9 .',-]+$/";
if(!preg_match($address_exp,$address1)) {
$error_message .= 'The Address you entered does not appear to be valid.<br />';
}
$postcode_exp = "/^[A-Za-z 0-9 .',-]+$/";
if(!preg_match($postcode_exp,$postcode)) {
$error_message .= 'The Postcode you entered does not appear to be valid.<br />';
}
$phone_exp = "/^[0-9 ]+$/";
if(!preg_match($phone_exp,$phone)) {
$error_message .= 'The Phone number you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "name: ".clean_string($name)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "address1: ".clean_string($address1)."\n";
$email_message .= "postcode: ".clean_string($postcode)."\n";
$email_message .= "phone: ".clean_string($phone)."\n";
$email_message .= "message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$whofrom=$_POST["email"];
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
надеюсь, что вы можете помочь мне, как я понятия не имею, как это сделать!
Почему? Зачем запрещать эти слова? Таким образом, вы ничего не стоите. Если они не могут ввести «имя» в качестве фиктивного имени, они просто вводят «naem» или «bob» или буквально * любую другую строку мусора *. – meagar
Как использовать элемент ввода [* placeholders *] (http://diveintohtml5.info/forms.html#placeholder)? Они являются родными в HTML5, и многие современные браузеры поддерживают их, и они могут быть помечены в старых браузерах; и они не отправляют * ничего * на сервер. – deceze
Кроме того, ваше регулярное выражение электронной почты нарушено и отклонит многие полностью действующие адреса электронной почты. Попробуйте '' /^[email protected]+\..+$/''. – meagar