filters - Contact Form 7 Custom Validation Doesn't Get Called

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

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 question

I'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 question

I'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
Add a comment  | 

1 Answer 1

Reset to default 3

First 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

相关推荐

  • filters - Contact Form 7 Custom Validation Doesn't Get Called

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信