• Hello there,

    I installed the plugin Really Simple CAPTCHA, put the [recpatcha] code in my form, put the site keey and secret key as well, but still it’s not displaying. I also tried to turn off al the other plugins, still not working. how can I fix it?

    • This topic was modified 6 years, 10 months ago by eliranseo.

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter eliranseo

    (@eliranseo)

    I did it. it worked for the first time, but when I refreshed the page, the reCAPTHCA has gone.

    How can I fix it?

    Same issue here.

    Console says ‘ReCAPTCHA couldn’t find user-provided function: recaptchaCallback’

    I did some digging and find out that the script with recaptchaCallback variable is not printing.

    Below condition is returning true and thus not printing the javascript ahead. If I comment this, recaptcha appears again.

    if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
    	return;
    }

    p.s. recaptcha was working fine earlier. I am using wordpress 4.9.2 and latest contact form 7.

    For now, I am removing the plugin’s action and adding mine. This works for me.

    remove_action( 'wp_footer', 'wpcf7_recaptcha_callback_script');
    add_action( 'wp_footer', 'as_recaptcha_callback_script');
    function as_recaptcha_callback_script() {
    	if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
    		return;
    	}
    ?>
    <script type="text/javascript">
    var recaptchaWidgets = [];
    var recaptchaCallback = function() {
    	var forms = document.getElementsByTagName( 'form' );
    	var pattern = /(^|\s)g-recaptcha(\s|$)/;
    
    	for ( var i = 0; i < forms.length; i++ ) {
    		var divs = forms[ i ].getElementsByTagName( 'div' );
    
    		for ( var j = 0; j < divs.length; j++ ) {
    			var sitekey = divs[ j ].getAttribute( 'data-sitekey' );
    
    			if ( divs[ j ].className && divs[ j ].className.match( pattern ) && sitekey ) {
    				var params = {
    					'sitekey': sitekey,
    					'type': divs[ j ].getAttribute( 'data-type' ),
    					'size': divs[ j ].getAttribute( 'data-size' ),
    					'theme': divs[ j ].getAttribute( 'data-theme' ),
    					'badge': divs[ j ].getAttribute( 'data-badge' ),
    					'tabindex': divs[ j ].getAttribute( 'data-tabindex' )
    				};
    
    				var callback = divs[ j ].getAttribute( 'data-callback' );
    
    				if ( callback && 'function' == typeof window[ callback ] ) {
    					params[ 'callback' ] = window[ callback ];
    				}
    
    				var expired_callback = divs[ j ].getAttribute( 'data-expired-callback' );
    
    				if ( expired_callback && 'function' == typeof window[ expired_callback ] ) {
    					params[ 'expired-callback' ] = window[ expired_callback ];
    				}
    
    				var widget_id = grecaptcha.render( divs[ j ], params );
    				recaptchaWidgets.push( widget_id );
    				break;
    			}
    		}
    	}
    };
    
    document.addEventListener( 'wpcf7submit', function( event ) {
    	switch ( event.detail.status ) {
    		case 'spam':
    		case 'mail_sent':
    		case 'mail_failed':
    			for ( var i = 0; i < recaptchaWidgets.length; i++ ) {
    				grecaptcha.reset( recaptchaWidgets[ i ] );
    			}
    	}
    }, false );
    </script>
    <?php
    }
    Thread Starter eliranseo

    (@eliranseo)

    Where did you put that code?

    function.php of theme. If you do not have a child theme, please create one and put this code there.

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