Answer the question
In order to leave comments, you need to log in
Why doesn't custom tag validation work in Contact form 7?
Hello!
Added my tag to Contact form 7
implemented validation of this field
Below is the code, why doesn't validation work? (the letter is sent to the mail, although it should not)
More precisely, the validation function itself works, why is the form sent, despite the fact that I entered invalid data in this field?
// добавляем свой тег(поле) для формы
function hfa_cf7_func() {
return "<span class=\"wpcf7-form-control-wrap email_hfa\"><input type=\"text\" name=\"email_hfa\" value=\"\" size=\"40\" class=\"wpcf7-form-control email required wpcf7-text wpcf7-validates-as-required form__field\" id=\"email_hfa\" aria-required=\"true\" aria-invalid=\"false\" placeholder=\"email\"></span>";
}
wpcf7_add_form_tag(array('email_hfa', 'email_hfa*'), 'hfa_cf7_func', array('name-attr' => true));
// добавляем правило валиации для тега(поля)
add_filter('wpcf7_validate_email_hfa', 'email_hfa_validation_filter', 10, 2);
function email_hfa_validation_filter($result, $tag) {
$value = isset($_POST['email_hfa']) ? $_POST['email_hfa'] : '';
if ( $value != "" ) { //если в поле есть символы - отдаем ошибку
$result['valid'] = false;
$result['reason'] = array( 'email_hfa' => 'NO!' );
}
return $result;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question