diff --git a/app/code/community/Studioforty9/Recaptcha/Block/Explicit.php b/app/code/community/Studioforty9/Recaptcha/Block/Explicit.php index 03bb7e6..1c521fb 100644 --- a/app/code/community/Studioforty9/Recaptcha/Block/Explicit.php +++ b/app/code/community/Studioforty9/Recaptcha/Block/Explicit.php @@ -178,7 +178,7 @@ public function getRecaptchaScript() $query = array( 'onload' => 'recaptchaOnloadCallback', - 'render' => 'explicit', + 'render' => $this->getSiteKey(), 'hl' => $lang ); diff --git a/app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml b/app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml index ae4bdb1..d0094be 100644 --- a/app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml +++ b/app/design/frontend/base/default/template/studioforty9/recaptcha/explicit.phtml @@ -36,34 +36,28 @@ $submitMethod = $this->getSubmitMethod() ? $this->getSubmitMethod() : 'form.subm var form = ; jQuery(form.form).one('click.captcha hover.captcha focus.captcha', function(){ jQuery(this).off('.captcha'); - var widgetId = grecaptcha.render(container, { - 'theme': "getTheme(); ?>", - 'type': "getType(); ?>", - 'badge': "getBadgeLocation(); ?>", - 'error-callback': function() { - recaptchaShowErrorAndRetry('', widgetId); - }, - 'callback': function(response) { - if (form.validator && form.validator.validate()){ - console.log('reCaptcha ('+widgetId+') passsed and form is valid'); - ; - } else { - console.log('reCaptcha ('+widgetId+') passsed but form not valid, resetting'); - grecaptcha.reset(widgetId); - } - } - }); - console.log('reCaptcha widget '+widgetId+' rendered'); - jQuery(container).attr('data-widget-id', widgetId); + $(form.form).on('submit', function (e) { + e.preventDefault(); - // Stop normal form submission, so we can trigger validation and the recaptcha challenge in the - // correct order. Actual form submission is done in the recaptcha callback that we specified in - // the grecaptcha.render() call. - jQuery(form.form).submit(function (event) { - if (form.validator.validate()) { - grecaptcha.execute(widgetId); - event.preventDefault(); - } + grecaptcha.ready(function() { + grecaptcha.execute("getSiteKey(); ?>", {action: 'submit'}).then(function(token) { + console.log('grecaptcha.ready'); + var form = ; + if (form.validator && form.validator.validate()) { + console.log('reCaptcha passsed and form is valid'); + jQuery('', { + type: 'hidden', + id: 'g-recaptcha-response', + name: 'g-recaptcha-response', + value: token + }).appendTo(jQuery('#recaptcha-').closest('form')[0]); + form.submit(); + } else { + console.log('reCaptcha passsed but form not valid, resetting'); + //grecaptcha.reset(); + } + }); + }); }); });