bariew / yii2-invisible-recaptcha

BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

Uncaught ReferenceError: grecaptcha is not defined #1

Open yaroslavolekh opened 5 years ago

yaroslavolekh commented 5 years ago

https://monosnap.com/file/sSLYmXftJHu6kpkBT8rp9t5FNEHb8V

You might wait for callback

yaroslavolekh commented 5 years ago

$this->getView()->registerJsFile('https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit', [ 'async' => 'async', 'defer' => 'defer' ]); ... return Html::activeHiddenInput($this->model, $this->attribute) . Html::button($this->buttonText, $options) . Html::tag('script', <<<JS window.recaptchaCallback_{$callbackRandomString} = function() { $('#{$inputId}').val($('#{$recaptchaId}').val()); $('#{$formId}').submit(); }

            window.onloadCallback = function() {
              grecaptcha.render('recaptchaButton{$callbackRandomString}'); 
            }

JS