Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the IsTrue validator against a simple form field #303

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ggioffreda
Copy link

@ggioffreda ggioffreda commented Nov 22, 2023

By defaulting to the field value, we allow IsTrue validation against any form field, without hardcoded field name "g-recaptcha-response" in the request.

This is useful for example:

  • when the "g-recaptcha-response" field cannot be sent with our request (neither through query string, or post, etc);
  • when a custom widget is rendering the field, the name of such field cannot be (or should not be) controlled;
  • when using third party UIs that support Symfony Forms and Validation but don't allow setting an out of scope variable to be sent to the server.

Example:

$builder->add('_captcha', CaptchaType::class, [
  'required' => true,
  'constraints' => [
    new NotNull(),
    new IsTrue(), // verification token will be sent as "_captcha"
  ],
]);

By defaulting to the field value, we allow IsTrue validation
against any form field, without hardcoded field name
"g-recaptcha-response" in the request.

This is useful for example:
- when the "g-recaptcha-response" field cannot be sent with
  our request (neither through query string, or post, etc);
- when a custom widget is rendering the field, the name of
  such field cannot be (or should not be) controlled;
- when using third party UIs that support Symfony Forms and
  Validation but don't allow seting an out of scope
  variable to be sent to the server.

Example:

```php
$builder->add('_captcha', CaptchaType::class, [
  'required' => true,
  'constraints' => [
    new NotNull(),
    new IsTrue(), // verification token will be sent as "_captcha"
]);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant