Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI'm trying to change the filter for email so that it reads "Email Address is Required". I check to is if it is empty().
My tag in Contact Form 7 is [email* your-email]
You can see here, I tried everything to change the filter response but nothing works.
add_filter( 'wpcf7_validate_email', 'custom_email_confirmation_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
function custom_email_confirmation_validation_filter( $result, $tag ) {
$result->invalidate( $tag, "Email Address is Required" );
if ( 'your-email' == $tag->name ) {
$your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
if ( empty($your_email) ) {
$result->invalidate( $tag, "Email Address is Required" );
} else {
$result->invalidate( $tag, "Email Address is Required" );
}
}
return $result;
}
What might I be missing?
Thanks
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 5 years ago.
Improve this questionI'm trying to change the filter for email so that it reads "Email Address is Required". I check to is if it is empty().
My tag in Contact Form 7 is [email* your-email]
You can see here, I tried everything to change the filter response but nothing works.
add_filter( 'wpcf7_validate_email', 'custom_email_confirmation_validation_filter', 20, 2 );
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
function custom_email_confirmation_validation_filter( $result, $tag ) {
$result->invalidate( $tag, "Email Address is Required" );
if ( 'your-email' == $tag->name ) {
$your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
if ( empty($your_email) ) {
$result->invalidate( $tag, "Email Address is Required" );
} else {
$result->invalidate( $tag, "Email Address is Required" );
}
}
return $result;
}
What might I be missing?
Thanks
Share Improve this question asked Jul 6, 2019 at 14:20 Best Dev TutorialsBest Dev Tutorials 4451 gold badge7 silver badges21 bronze badges 1- I noticed, my custom validation works if the field is not marked as required. Not sure why that is, as the filter is exactly how the contact form 7 documentation is. – Best Dev Tutorials Commented Jul 6, 2019 at 15:43
1 Answer
Reset to default 3First of all if you are already checking if the field is empty with that function, there's no need to use * in the backoffice [email* your-email].
In any case, it's not working because is_required()
executes first than your function.
Solutions:
1) Remove the * in the backend
OR
2) Change the priority
// From 20 to 5 should work
// You only need to apply this to this filter as it is the one for required fields
add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 5, 2 );
Hope it helps!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340707a4623313.html
评论列表(0条)