Skip to content

Commit 418c3a7

Browse files
Bahaa OdehBahaa Odeh
authored andcommitted
add widget
1 parent 29cbb4f commit 418c3a7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

RecaptchaV3Widget.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,24 @@ public function run()
6363
$this->field->template = "{input}\n{error}";
6464
$formId = $this->field->form->id;
6565
$inputId = Html::getInputId($this->model, $this->attribute);
66+
$callbackRandomString = time();
67+
68+
$options = array_merge([
69+
'onClick' => "recaptchaCallback_{$callbackRandomString}()"
70+
], $this->options);
71+
6672

6773
return
6874
Html::tag('script', <<<JS
69-
grecaptcha.ready(function() {
70-
grecaptcha.execute('{$this->_component->site_key}', {action: '{$this->actionName}'}).then(function(token) {
71-
alert(token);
72-
$('#{$inputId}').val(token);
73-
$('#{$formId}').submit();
74-
});
75-
});
75+
var recaptchaCallback_{$callbackRandomString} = function() {
76+
grecaptcha.ready(function() {
77+
grecaptcha.execute('{$this->_component->site_key}', {action: '{$this->actionName}'}).then(function(token) {
78+
alert(token);
79+
$('#{$inputId}').val(token);
80+
$('#{$formId}').submit();
81+
});
82+
});
83+
}
7684
JS
7785
)
7886
. Html::activeHiddenInput($this->model, $this->attribute)

0 commit comments

Comments
 (0)