Support » Plugin: Contact Form 7 » Recaptcha javascript error

  • latcomsystems

    (@latcomsystems)


    Line 60 in recaptcha.php gets an error grecpatcha is not defined
    because it is loaded in the footer but all the other scripts are loaded with DEFER attribute by default, so grecaptcha does not exist at this point.

    Author needs to surround the inline javasript with:

    window.addEventListener(‘DOMContentLoaded’, function() {
    ( function( grecaptcha, sitekey ) {……….
    });

    I fixed this on my client’s site and turned off updates to this plugin until a fix is published.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Seems I’ve fond a solution.

    On my client’s website the link for recaptcha (https://www.google.com/recaptcha/api.js?render=SECRET-KEY&ver=3.0) responds 400 Bad request.
    Seems he didn’t add the domain to the allowed one.

    But, if you’re telling that your solution is working, maybe you have some issues and conflicts in your custom code?

    Thanks.

    You should set priority to 1 instead of 40 at line 45

    add_action( ‘wp_footer’, ‘wpcf7_recaptcha_onload_script’, 1, 0 );

    @cag8f I replied according to the result of the thread.

    
    diff --git a/htdocs/wp-content/plugins/contact-form-7/modules/recaptcha.php b/htdocs/wp-content/plugins/contact-form-7/modules/recaptcha.php
    index 5cb45e8..19e74ce 100755
    --- a/htdocs/wp-content/plugins/contact-form-7/modules/recaptcha.php
    +++ b/htdocs/wp-content/plugins/contact-form-7/modules/recaptcha.php
    @@ -42,7 +42,7 @@ function wpcf7_recaptcha_add_hidden_fields( $fields ) {
            ) );
     }
     
    -add_action( 'wp_footer', 'wpcf7_recaptcha_onload_script', 40, 0 );
    +add_action( 'wp_footer', 'wpcf7_recaptcha_onload_script', 1, 0 );
     
     function wpcf7_recaptcha_onload_script() {
            $service = WPCF7_RECAPTCHA::get_instance();
    @@ -57,7 +57,6 @@ function wpcf7_recaptcha_onload_script() {
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Recaptcha javascript error’ is closed to new replies.