EWZRecaptchaBundle icon indicating copy to clipboard operation
EWZRecaptchaBundle copied to clipboard

Allow using the IsTrue validator against a simple form field

Open ggioffreda opened this issue 2 years ago • 0 comments

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"
  ],
]);

ggioffreda avatar Nov 22 '23 01:11 ggioffreda