• Hello,

    I get this annoying error in my console logs : “grecaptcha.execute is not a function”.
    (I’m in Contact Form 7 v5.1.4 but I think it appeared before)

    When I click on the error, I see the error comes from wp-content/plugins/contact-form-7/modules/recaptcha.php, line 78.

    I’ve searched on the web for nearly an hour, when I came here: https://developers.google.com/recaptcha/docs/v3
    From that page, it seems like the code lacks the “grecaptcha.ready” part in order to work properly.

    I added it before the call to grecaptcha.execute in the code, and now the error seems to be gone.

    I’m creating this topic because I guess other people have/will have the same issue as me, and also to know if there is a better solution (or if this is even a solution).

    I’m afraid that this “fix” will be overwritten when I update Contact Form 7 next time…

    Thanks!

    • This topic was modified 5 years, 3 months ago by eldoir.
    • This topic was modified 5 years, 3 months ago by eldoir.
Viewing 2 replies - 1 through 2 (of 2 total)
  • hi i have your same problem can i ask you how you solved? what did you change precisely?

    Thread Starter eldoir

    (@eldoir)

    Hi @giorgiodir,
    I said it in my message but maybe it wasn’t clear, in the file wp-content/plugins/contact-form-7/modules/recaptcha.php, I added a call to grecaptcha.ready() just before the call to grecaptcha.execute(), according to the Google page I mentioned.
    If you’re not a developer, and you have the same version of Contact Form 7 as me (v.5.1.4, the last one), then you can just replace the lines 77-99 of the file with the following ones:

    execute: function( action ) {
      grecaptcha.ready(function() {
        grecaptcha.execute(
          sitekey,
          { action: action }
        ).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;
    	  }
    	}
          }
        });
      });
    },
    • This reply was modified 5 years, 3 months ago by eldoir.
    • This reply was modified 5 years, 3 months ago by eldoir.
    • This reply was modified 5 years, 3 months ago by eldoir.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error: grecaptcha.execute is not a function’ is closed to new replies.