Forum Replies Created

Viewing 1 replies (of 1 total)
  • Hi Guy,

    When the captcha validation fails, you can return a WP_Error on the jetpack_contact_form_is_spam filter to abort the process submission and modify the contact form HTML. Example:

    add_filter( 'jetpack_contact_form_is_spam', function ( $is_spam, $submission ) {
    $is_captcha_valid = false; // Replace by calling your custom validation.

    if ( ! $is_captcha_valid ) {
    // My custom error.
    $error = new \WP_Error( 'captcha_failed', __( 'CAPTCHA verification failed. Please try again.') );

    // Modify the contact form HTML.
    add_filter( 'jetpack_contact_form_html', function ( $format_html) use ( $error ) {
    return '<pre>' . $error->get_error_message() . '</pre>' . $format_html;
    } );

    // Return a custom error to abort the form process submission.
    return $error;
    }

    return false;
    }, 10, 2 );

    Please let me know if it works.

Viewing 1 replies (of 1 total)