File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change 27
27
28
28
Once the extension is installed, simply use it in your code by :
29
29
30
+ add this to your components main.php
31
+
32
+ ``` php
33
+ 'components' => [
34
+ ...
35
+ 'recaptchaV3' => [
36
+ 'class' => 'Baha2Odeh\RecaptchaV3\RecaptchaV3',
37
+ 'site_key' => '###',
38
+ 'secret_key' => '###',
39
+ ],
40
+
41
+ ```
42
+
43
+ and in your model
44
+
45
+ acceptance_score the minimum score for this request (0.0 - 1.0) or null
46
+
30
47
``` php
31
- <?= \Baha2Odeh\RecaptchaV3\AutoloadExample::widget(); ?>```
48
+ public $code;
49
+
50
+ public function rules(){
51
+ return [
52
+ ...
53
+ [['code'],RecaptchaV3Validator::className(),'acceptance_score'=>null]
54
+ ];
55
+ }
56
+ ```
57
+
58
+ ``` php
59
+ <?= $form->field($model,'code')->widget(\Baha2Odeh\RecaptchaV3\RecaptchaV3Widget::className());
60
+ ```
61
+
62
+
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class RecaptchaV3Validator extends Validator
30
30
31
31
32
32
/**
33
- * the score for this request (0.0 - 1.0)
33
+ * the minimum score for this request (0.0 - 1.0)
34
34
* @var null|int
35
35
*/
36
36
public $ acceptance_score = null ;
@@ -62,7 +62,6 @@ public function init()
62
62
*/
63
63
protected function validateValue ($ value )
64
64
{
65
-
66
65
$ result = $ this ->_component ->validateValue ($ value );
67
66
if ($ result === false ){
68
67
return [$ this ->message , []];
Original file line number Diff line number Diff line change @@ -72,6 +72,12 @@ public function run()
72
72
73
73
74
74
$ this ->view ->registerJs (<<<JS
75
+
76
+ grecaptcha.ready(function() {
77
+ grecaptcha.execute(' {$ this ->_component ->site_key }', {action: ' {$ this ->actionName }'}).then(function(token) {
78
+ $('# {$ inputId }').val(token);
79
+ });
80
+ });
75
81
$('# {$ formId }').on('beforeSubmit',function(){
76
82
if(!$('# {$ inputId }').val()){
77
83
grecaptcha.ready(function() {
@@ -80,9 +86,9 @@ public function run()
80
86
$('# {$ formId }').submit();
81
87
});
82
88
});
83
- return true;
84
- }else{
85
89
return false;
90
+ }else{
91
+ return true;
86
92
}
87
93
});
88
94
JS
You can’t perform that action at this time.
0 commit comments