You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
> **NOTE**: The configuration options differ between Version 2 and Version 3 of the reCAPTCHA system. Some of the previous options have no effect on Version 3.
36
+
35
37
Add the following to your config file:
36
38
37
-
**NOTE**: If you're using symfony 4, the config will be in `config/packages/ewz_recaptcha.yaml`. The local dev enviroment has its own config in `config/packages/dev/ewz_recaptcha.yaml`.
39
+
> **NOTE**: If you're using symfony 4, the config will be in `config/packages/ewz_recaptcha.yaml`. The local dev enviroment has its own config in `config/packages/dev/ewz_recaptcha.yaml`.
40
+
41
+
#### Main configuration for both v2 and v3
42
+
43
+
The version setting determines which configuration options are available. Set the version corresponding to your Google reCAPTCHA settings (valid values: 2 or 3):
38
44
39
45
```yaml
40
46
# app/config/config.yml
41
47
42
48
ewz_recaptcha:
43
-
public_key: here_is_your_public_key
44
-
private_key: here_is_your_private_key
45
-
# Not needed as "%kernel.default_locale%" is the default value for the locale key
46
-
locale_key: %kernel.default_locale%
49
+
// ...
50
+
version: 2
47
51
```
48
52
49
-
**NOTE**: This Bundle lets the client browser choose the secure https or unsecure http API.
53
+
You can easily disable reCAPTCHA (for example in a local or test environment):
50
54
51
-
If you want to use the language default for the reCAPTCHA the same as the
52
-
request locale you must activate the resolver (deactivated by default):
55
+
```yaml
56
+
# app/config/config.yml
57
+
58
+
ewz_recaptcha:
59
+
// ...
60
+
enabled: false
61
+
```
62
+
63
+
Enter the public and private keys here:
53
64
54
65
```yaml
55
66
# app/config/config.yml
56
67
57
68
ewz_recaptcha:
58
69
// ...
59
-
locale_from_request: true
70
+
public_key: here_is_your_public_key
71
+
private_key: here_is_your_private_key
72
+
60
73
```
61
74
62
-
You can easily disable reCAPTCHA (for example in a local or test environment):
75
+
`www.google.com` is blocked in Mainland China, you can override the default server like this (See https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally for further information):
63
76
64
77
```yaml
65
78
# app/config/config.yml
66
79
67
80
ewz_recaptcha:
68
81
// ...
69
-
enabled: false
82
+
api_host: recaptcha.net
70
83
```
71
84
72
-
Or even load reCAPTCHA using Ajax:
85
+
#### v2 only Configuration
86
+
87
+
Sets the default locale:
73
88
74
89
```yaml
75
90
# app/config/config.yml
76
91
77
92
ewz_recaptcha:
78
93
// ...
79
-
ajax: true
94
+
# Not needed as "%kernel.default_locale%" is the default value for the locale key
95
+
locale_key: %kernel.default_locale%
80
96
```
81
97
82
-
`www.google.com` is blocked in Mainland China, you can override the default server like this:
98
+
**NOTE**: This Bundle lets the client browser choose the secure https or unsecure http API.
99
+
100
+
If you want to use the language default for the reCAPTCHA the same as the
101
+
request locale you must activate the resolver (deactivated by default):
83
102
84
103
```yaml
85
104
# app/config/config.yml
86
105
87
106
ewz_recaptcha:
88
107
// ...
89
-
api_host: recaptcha.net
108
+
locale_from_request: true
90
109
```
91
110
111
+
You can load the reCAPTCHA using Ajax:
112
+
113
+
```yaml
114
+
# app/config/config.yml
115
+
116
+
ewz_recaptcha:
117
+
// ...
118
+
ajax: true
119
+
```
92
120
You can add HTTP Proxy configuration:
93
121
94
122
```yaml
@@ -101,7 +129,6 @@ ewz_recaptcha:
101
129
port: 3128
102
130
auth: proxy_username:proxy_password
103
131
```
104
-
105
132
In case you have turned off the domain name checking on reCAPTCHA's end, you'll need to check the origin of the response by enabling the ``verify_host`` option:
106
133
107
134
```yaml
@@ -131,10 +158,36 @@ return static function (ContainerConfigurator $configurator): void
131
158
};
132
159
```
133
160
161
+
#### v3 only Configuration
162
+
163
+
For the v3 reCAPTCHA an information badge is shown. If you inform your users about using the reCAPTCHA on another way, you can hide it with the following option (see https://developers.google.com/recaptcha/docs/faq#hiding-badge for further information):
164
+
165
+
```yaml
166
+
# app/config/config.yml
167
+
168
+
ewz_recaptcha:
169
+
// ...
170
+
hide_badge: true
171
+
```
172
+
173
+
To modify the default threshold score of 0.5 set this option (see https://developers.google.com/recaptcha/docs/v3#interpreting_the_score for further information):
174
+
175
+
```yaml
176
+
# app/config/config.yml
177
+
178
+
ewz_recaptcha:
179
+
// ...
180
+
score_threshold: 0.6
181
+
```
182
+
134
183
Congratulations! You're ready!
135
184
136
185
## Basic Usage
137
186
187
+
> **NOTE**: The basic usage differs between Version 2 and Version 3 of the reCAPTCHA system.
188
+
189
+
### v2 Usage
190
+
138
191
When creating a new form class add the following line to create the field:
139
192
140
193
```php
@@ -276,7 +329,6 @@ public function buildForm(FormBuilder $builder, array $options)
276
329
// ...
277
330
```
278
331
279
-
280
332
The form template resource is now auto registered via an extension of the container.
281
333
However, you can always implement your own custom form widget.
282
334
@@ -372,3 +424,158 @@ If you want to use a custom theme, put your chunk of code before setting the the
372
424
},
373
425
} }) }}
374
426
```
427
+
428
+
### v3 Usage
429
+
430
+
When creating a new form class add the following line to create the field:
431
+
432
+
``` php
433
+
<?php
434
+
435
+
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
You can pass the action to reCAPTCHA with the "action_name" option (see https://developers.google.com/recaptcha/docs/v3#actions for further information)::
446
+
447
+
``` php
448
+
<?php
449
+
450
+
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints as Recaptcha;
468
+
469
+
/**
470
+
* @Recaptcha\IsTrueV3
471
+
*/
472
+
public $recaptcha;
473
+
```
474
+
475
+
Another method would consist to pass the validation constraints as an options of your FormType. This way, your data class contains only meaningful properties.
476
+
If we take the example from above, the buildForm method would look like this. You have to also set ```constraints```:
477
+
478
+
``` php
479
+
<?php
480
+
481
+
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaV3Type;
482
+
use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrueV3;
0 commit comments