Answer the question
In order to leave comments, you need to log in
PHP mailer sends unvalidated messages, what to add?
I made my site according to the training course with ready-made js, php scripts. The php mailer form processes sending a message, but sends all messages, including those that did NOT pass validation. There is validation in js, it highlights lines in red if they are incorrectly filled.
function validateForms(form){
$(form).validate({
rules: {
name: {
required: true,
minlength: 2
},
phone: "required",
email: {
required: true,
email: true
}
},
messages: {
name: {
required: "Please enter your name",
minlength: jQuery.validator.format("Enter {0} characters!")
},
phone: "Please enter your phone number",
email: {
required: "Please , enter your email",
email: "Invalid email address"
}
}
});
}
validateForms('#consultation-form');
validateForms('#consultation form');
validateForms('#order form');
$('input[name=phone]').
But there is a message sending, if you click Send. What needs to be added to js, what is the condition so that messages from the form that did not pass validation are not sent? Now function validateForms(form) { is }, then there seems to be no property where it is written to send only validated forms: $('form').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST ",
url: "mailer/smart.php",
data: $(this).serialize()
}).done(function() {
$(this).find("input").val("");
$ ('#consultation, #order').fadeOut();
$('.overlay, #thanks').fadeIn('slow');
$('form' .trigger('reset');
});
return false;
});
And another question about captcha: if you put a ready-made Google captcha, do you need to register validation in js too?
Answer the question
In order to leave comments, you need to log in
You need to do a validation check:
$('form').submit(function(e) {
if (валидация === успех) {
$.ajax({
type: "POST",
url: "mailer/smart.php",
...
} else {
появление ошибки, если валидация не пройдена
}
}
$('form').submit(function(e) {
console.log(validateForms('#order form'););
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question