• Resolved madu1234

    (@madu1234)


    After activating google reCAPTCHA and following the WP Tutorial: Adding reCAPTCHA to the Job/Resume Submission Form. The reCAPTCHA works fine when you select ARE YOU HUMAN BUTTON and also ask for image identification step for authentication. Then when you submit the form it shows: The Human Test Field please try again.

    We have tried everything in resolving the issue but to no avail. Please help with this problem.

    https://www.ads-software.com/plugins/wp-job-manager/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Please post your full code within backticks here (`) so we can see what code you have.

    Also, let us know what other plugins you’re running, such as field editor.

    Thread Starter madu1234

    (@madu1234)

    HI, i used all the same from here

    https://wpjobmanager.com/document/tutorial-adding-recaptcha-job-submission-form/

    just change the keys.

    <?php
    // Define your keys here
    define( ‘RECAPTCHA_SITE_KEY’, ‘XXX’ );
    define( ‘RECAPTCHA_SECRET_KEY’, ‘XXX’ );

    // Enqueue Google reCAPTCHA scripts
    add_action( ‘wp_enqueue_scripts’, ‘recaptcha_scripts’ );

    function recaptcha_scripts() {
    wp_enqueue_script( ‘recaptcha’, ‘https://www.google.com/recaptcha/api.js&#8217; );
    }

    // Add reCAPTCHA to the job submission form
    add_action( ‘submit_job_form_company_fields_end’, ‘recaptcha_field’ );

    function recaptcha_field() {
    ?>
    <fieldset>
    <label>Are you human?</label>
    <div class=”field”>
    <div class=”g-recaptcha” data-sitekey=”<?php echo RECAPTCHA_SITE_KEY; ?>”></div>
    </div>
    </fieldset>
    <?php
    }

    // Validate
    add_filter( ‘submit_job_form_validate_fields’, ‘validate_recaptcha_field’ );

    function validate_recaptcha_field( $success ) {
    $response = wp_remote_get( add_query_arg( array(
    ‘secret’ => RECAPTCHA_SECRET_KEY,
    ‘response’ => isset( $_POST[‘g-recaptcha-response’] ) ? $_POST[‘g-recaptcha-response’] : ”,
    ‘remoteip’ => isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ? $_SERVER[‘HTTP_X_FORWARDED_FOR’] : $_SERVER[‘REMOTE_ADDR’]
    ), ‘https://www.google.com/recaptcha/api/siteverify&#8217; ) );

    if ( is_wp_error( $response ) || empty( $response[‘body’] ) || ! ( $json = json_decode( $response[‘body’] ) ) || ! $json->success ) {
    return new WP_Error( ‘validation-error’, ‘”Are you human” check failed. Please try again.’ );
    }

    return $success;
    }

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Did you change the keys to your own or not?

    Thread Starter madu1234

    (@madu1234)

    yes we did change the keys

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Is the exact error shown:

    "Are you human" check failed. Please try again.

    ?

    Thread Starter madu1234

    (@madu1234)

    yes

    Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Then the API request is failing. 2 possible causes:

    1. You put the API keys in wrong
    2. Your server cannot communicate with google servers. Host may be blocking the request.

    site key and secret key —- would i be correct in thinking we only need to change the XXX and leave the rest as is?

    this is what i have done.
    from the comment above…..seems i have all in place…
    Do you recommend i call my hosting company then?

    Plugin Contributor Adam Heckler

    (@adamkheckler)

    site key and secret key —- would i be correct in thinking we only need to change the XXX and leave the rest as is?

    Correct.

    Do you recommend i call my hosting company then?

    Yeah, they might be able to run some tests to make sure your server can communicate with Google, which might be the issue now.

    Thanks!

    rimoreno

    (@rimoreno)

    i got this very same problem and i checked my keys, i checked my server and everything looks good.

    the only part that i have change on the code is what is in bold due to the fact that i use field editor.

    thanks in advance for your help

    here is my snippet.

    ———————————
    Job Manager Recaptcha
    ———————————— */

    define( ‘RECAPTCHA_SITE_KEY’, ‘i put in my keys here’ );
    define( ‘RECAPTCHA_SECRET_KEY’, ‘i put in my keys here’ );
    // Enqueue Google reCAPTCHA scripts
    add_action( ‘wp_enqueue_scripts’, ‘recaptcha_scripts’ );
    function recaptcha_scripts() {
    wp_enqueue_script( ‘recaptcha’, ‘https://www.google.com/recaptcha/api.js&#8217; );
    }
    // Add reCAPTCHA to the job submission form
    add_action( ‘submit_job_form_job_fields_end’, ‘recaptcha_field’ );
    function recaptcha_field() {
    ?>
    <fieldset>
    <label>Are you human?</label>
    <div class=”field”>
    <div class=”g-recaptcha” data-sitekey=”<?php echo RECAPTCHA_SITE_KEY; ?>”></div>
    </div>
    </fieldset>
    <?php
    }
    // Validate
    add_filter( ‘submit_job_form_validate_fields’, ‘validate_recaptcha_field’ );
    function validate_recaptcha_field( $success ) {
    $response = wp_remote_get( add_query_arg( array(
    ‘secret’ => RECAPTCHA_SECRET_KEY,
    ‘response’ => isset( $_POST[‘g-recaptcha-response’] ) ? $_POST[‘g-recaptcha-response’] : ”,
    ‘remoteip’ => isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ? $_SERVER[‘HTTP_X_FORWARDED_FOR’] : $_SERVER[‘REMOTE_ADDR’]
    ), ‘https://www.google.com/recaptcha/api/siteverify&#8217; ) );
    if ( is_wp_error( $response ) || empty( $response[‘body’] ) || ! ( $json = json_decode( $response[‘body’] ) ) || ! $json->success ) {
    return new WP_Error( ‘validation-error’, ‘”Are you human” check failed. Please try again.’ );
    }
    return $success;
    }
    /*————————————————————————————
    Submit resume
    ————————————————————————————–*/
    add_action( ‘submit_resume_form_resume_fields_end’, ‘recaptcha_field’ );
    add_filter( ‘submit_resume_form_validate_fields’, ‘validate_recaptcha_field’ );

    /*————————————————————————————
    Applications
    ————————————————————————————–*/
    add_action( ‘job_application_form_fields_end’, ‘recaptcha_field’ );
    add_filter( ‘application_form_validate_fields’, ‘validate_recaptcha_field’ );

    Plugin Contributor Adam Heckler

    (@adamkheckler)

    @rimoreno: Please create your own thread per the Forum Welcome policy:

    https://codex.www.ads-software.com/Forum_Welcome#Where_To_Post

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘reCAPTCHA code not working’ is closed to new replies.