• Resolved alex160678

    (@alex160678)


    Hi, I keep getting this error:

    Uncaught TypeError: grecaptcha.execute is not a function

    This issue appears on the latest version ( 3.0.1). Latest WP version is installed 5.2.3.

    After I deactivate GDPR Cookie Compliance plugin reCaptcha is not giveing any error. How can I safely use reCaptcha and GDPR Cookie Compliance plugin?

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Moove Agency

    (@mooveagency)

    Hi @alex160678,

    Thanks for using our plugins.

    We have checked the reCaptha v3 issue, and the problem is coming from Contact Form 7 plugin. In their javascript they are using a function which will parse all the forms not only the CF7 form: var forms = document.getElementsByTagName( ‘form’ );
    Our plugin uses checkboxes where the users can enable / disable the cookies, these are wrapped with form tags.
    You can ask CF7 support team to fix their plugin to parse only their forms and keep the rest of the forms in the site without reCaptcha validations.

    Hope this makes sense.

    Thread Starter alex160678

    (@alex160678)

    Hi,

    Thanks for the awnser. I will take it up with the CF7 guys.

    Regards,
    Alex

    Hi,

    I’ve got the same bug on many sites.

    As @alex160678 explains in this ticket https://www.ads-software.com/support/topic/recaptcha-v3-error-3/ the bug occurs when both plugins are active.

    I made some tests and I’ve found:

    No js error

    • Tab 1: Strictly necessary cookies: ON
    • Tab 2: Google Analytics: OFF

    js error

    • Tab 1: Strictly necessary cookies: ON
    • Tab 2: Google Analytics: ON

    I hope it can help.

    Thanks

    Plugin Author Moove Agency

    (@mooveagency)

    Hi @alex160678 and @jairoochoa

    Hi @alex160678

    This is not a bug in our plugin, the bug is in the Contact Form 7 plugin which checks all the form changes, not only the Contact Form 7 forms.

    We are using forms in our plugin, otherwise the switches (on / off) couldn’t work. And because our plugin is JavaScript based plugin, we change the switchers by javascript after page is loaded, so once the site visitors opens the popup screen, they will see the right consent settings.

    The issue should be fixed in CF7 plugin to NOT check ALL the forms on the site and activate the recaptcha, activate it only for their forms.

    Even if you have an independent form on your theme, or you are using a subscribe to newsletter plugin, the reCaptcha error appears because of wrong coding.

    This is the ticket opened on CF7: https://www.ads-software.com/support/topic/recaptcha-v3-error-3/

    The function below is part of the CF7 integration, they have to fix it by wrapping the code in file /contact-form-7/modules/recaptcha.php line 78 – 96, so their plugin should wait until the captcha will be ready! This is the instruction from Google too, what is the correct implementation of the reCaptcha:
    https://developers.google.com/recaptcha/docs/v3

    It’s quite simple, before grecaptcha.execute will be called, they have to check if it’s ready…

    This is the current code in their plugin (buggy):

    grecaptcha.execute(
    				sitekey,
    				{ action: action }
    			).then( function( token ) {
    				var forms = document.getElementsByTagName( 'form' ); <- please note this is not correct, they only have to parse the CF7 forms and keep the rest as it is!
    
    				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;
    						}
    					}
    				}
    			} );

    This should be the fixed code (fixed, underlined the missing part):

    grecaptcha.ready(function() { <- missing from the current CF7 plugin!
    				grecaptcha.execute(
    					sitekey,
    					{ action: action }
    				).then( function( token ) {
    					var forms = document.getElementsByClassName( 'wpcf7' ); <- this is fixed, only get CF7 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;
    							}
    						}
    					}
    				} );
    			}); <- missing closing tags for CF7

    Hope this makes sense.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @mooveagency Stop calling topics here “tickets”. When you and @jairoochoa do that you are both perpetuating that you have customers here. You don’t, there are no customers on this site.

    There are only open source users of free code that you’ve donated to the community. This isn’t word play and it’s important or your users will be misinformed and think you’re not a volunteer and they’re your customers. They’re not and you are a volunteer here.

    Dear @jdembowski

    I’m sorry if I did something wrong.

    I’m Spanish native, not English native, and I didn’t notice the difference between topic and ticket that you point.

    I simply ask questions if in doubt and I answer questions if I can help.
    I’ve never associated the word ticket to business, just to questions.

    I always entered WordPress Support with the intention of helping.

    Sorry again for misunderstood.

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘reCaptcha V3 error’ is closed to new replies.