Support » Plugin: Contact Form 7 » grecaptcha is not defined

  • Resolved blindpet

    (@blindpet)


    After updating to the latest version I now get this error ‘grecaptcha is not defined’:

    	var wpcf7recaptcha = {
    		execute: function() {
    			grecaptcha.execute(
    				sitekey,
    				{ action: 'homepage' }
    			).then( function( token ) {
    				var forms = document.getElementsByTagName( 'form' );
    
    				for ( var i = 0; i < forms.length; i++ ) {
    					var fields = forms[ i ].getElementsByTagName( 'input' );
    
    					for ( var j = 0; j < fields.length; j++ ) {
    						var field = fields[ j ];
    
    						if ( 'g-recaptcha-response' === field.getAttribute( 'name' ) ) {
    							field.setAttribute( 'value', token );
    							break;
    						}
    					}
    				}
    			} );
    		}
    	};
    
    	grecaptcha.ready( wpcf7recaptcha.execute );

    The v3 recaptcha is also not working very well and lets a lot more spam in 🙁

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Here is another error from the console:

    Uncaught TypeError: wpcf7.initForm is not a function
        at HTMLFormElement.<anonymous> (scripts.js:33)
        at Function.each (jquery.js:2)
        at a.fn.init.each (jquery.js:2)
        at HTMLDocument.<anonymous> (scripts.js:31)
        at i (jquery.js:2)
        at Object.add [as done] (jquery.js:2)
        at n.fn.init.n.fn.ready (jquery.js:2)
        at a.fn.init.n.fn.init (jquery.js:2)
        at new a.fn.init (jquery-migrate.min.js:2)
        at n (jquery.js:2)

    Rolling back to 5.1 has resolved this issue so the bug exists in 5.1.1 it seems

    Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thank you, rolling back to 5.1.0 fixed the issue with the contact form not sending, I believe I was not getting any spam because 5.1.1 broke with its update not due to any improvements with recaptcha in 5.1.1. I do have wp_footer in my theme I believe so this wouldn’t explain the failure I don’t think

    • This reply was modified 1 year, 4 months ago by blindpet.

    For those having the same problem but can’t ask their theme developer to make an updated, you can add <script src=”google.com/recaptcha/api.js” async defer></script> just before </head> to make contact form 7 work again.

    fatherb = the hero we don’t deserve! Thank you, kind sir!

    This can also be caused by CloudFlare’s Rocket Loader!

    For a simple fix, I installed a WP Plugin: https://wordpress.org/plugins/wp-cloudflare/

    Adding the following to Turn RocketScript Off For:
    https://www.google.com/recaptcha/api.js

    Then purge the Cloudflare cache and WP caching plugins. Alternatively, this can also be done through CloudFlare page rules, if you have any left.

    OrlandoWebDev

    (@orlandowebdev)

    I had this issue too, I tried several of the fixes above. I had wp_footer(), I was using v5.1.1. But the user inserted reCaptcha v2 keys instead of reCaptcha v3 keys, I put in the v3 keys and it worked just fine.

    I’ve the same error and also I do not load the CSS of the child theme. But when I add the script at least the css is loaded. But the error keeps coming up in the console.

    I am not sure this will help you now or not. I had same issue and I updated reCAPTCHA key with V3. Might be you had old v2 key configured.
    Ref : https://nimb.ws/odmsKG
    Please make sure all reCAPTCHA should use version 3 now.

    I hope this will help you.

    If you use the “Async JavaScript” plugin, you need to insert “api.js” under “Scripts to Exclude”.
    So neither async nor defer get applied during page load.
    Problem solved.

    @zenben

    Magic man ! 🙂

    johnwbyrd

    (@johnwbyrd)

    Dear future Googlers,

    This problem can be best solved by looking at any error outputs in your browser console (F12 and Console under Chrome.)

    First, check that https://www.google.com/api/recaptcha.js is being loaded by your plugin code, and is present in the HTML of your web site.

    Next, check any caching plugins or services. This file MUST be loaded before the grecaptcha snippet that actually performs the recaptcha. Some caching plugins reorder Javascript loads, such that the recaptcha.js file is not loaded in time before the captcha callback code is run.

    In my WordPress setup, I worked around by adding “captcha” to the list of strings for URIs that the JavaScript caching mechanism should not cache.

    Under LiteSpeed Cache Settings, under Tuning, I set Javascript Excludes to include the word captcha.

    Your caching system will need to be set similarly, to exclude any captcha js from reordering.

    This fixed my problem.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.