Google Captcha does not reload on form errors

Google Captcha does not reload, I can’t figure out why…

First I load it on link click- it opens modal and loads Captcha- everything is ok here, but when I click on Form’s Submit button- Captcha should reload, but it never happens.

Here is my code :slight_smile:

Maybe my logic is wrong? I can’t understand what I’m doing wrong here. Please help :slight_smile:

(function ($) {

    'use strict';

    $(window).load(function () {

        if ($('body').hasClass('page-id-97')){

          	//THIS WORKS OK

            $('.manual-download-link').on('click', function () {

                var thisButtonData = $(this).data('popup');

                var popUpContainer = $('#popmake-'+thisButtonData);

                popUpContainer.find('.g-recaptcha').each(function (index, element) {

                    // Ensure field is empty before rendering CAPTCHA
                    if ($(this).is(':empty')) {
                        // Site key
                        var site_key = $(this).attr('data-sitekey');
                        // CAPTCHA theme
                        var theme = $(this).attr('data-theme');
                        // Native DOM element
                        var element = $(this).get(0);
                        // Render CAPTCHA
                        grecaptcha.render(element, {'sitekey': site_key, 'theme': theme});
                    }
                });

            });

            $('div.gform_footer input').on('click', function () {

                $(document).bind('gform_post_render', function () {

                  	var inputButton = $(this);

                		var inputForm = inputButton.parents('form');
                  
                    inputForm.each(function (index, element) {

                        var n = $(this).find('.g-recaptcha');
                      
                      	//THIS DOES NOT LOAD CAPCTHA- WHY?! ;(
                      
                        // Ensure field is empty before rendering CAPTCHA
                        if (n.is(':empty')) {
                            // Site key♂
                            var site_key = n.attr('data-sitekey');
                            // CAPTCHA theme
                            var theme = n.attr('data-theme');
                            // Native DOM elemento
                            // var element = $(this).get(0);
                            var element = n.get(0);
                            // Render CAPTCHA
                            grecaptcha.render(
                                element, {
                                    'sitekey': site_key,
                                    'theme': theme
                                }
                            );
                        }
                    });
                });
            })
        }
    });
})(jQuery);

Hi,

A cursory look at the code you posted doesn’t reveal any obvious errors. Would it be possible to post a working example (in a JSFiddle or something)?

Hi :slight_smile:
Sorry, it’s WP website, working on it locally…
I’ll try to run it on ngrok :slight_smile: will let you know shortly :slight_smile:

ngrok doesn’t work, because or non-relative urls and plugin doesn’t help…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.