UndefinedOffset / silverstripe-nocaptcha

A spam protector and form field using Google's reCAPTCHA v2 or optionally a foundation v3 implementation
BSD 3-Clause "New" or "Revised" License
31 stars 37 forks source link

ENHANCEMENT: Add ability to add exempt actions from recaptcha checks #69

Closed scott1702 closed 3 years ago

scott1702 commented 3 years ago

Ran into a scenario where a form could have actions such as "Cancel form" or "Save form" which may want to bypass validation in which case the user should not be presented with a recaptcha.

There's also a secondary issue which this change allows a developer to bypass where there are multiple actions with type="submit". e.g. if there was a Submit and Cancel action on the form and the user clicks the cancel action, normally a form would pass action_cancel in the FormData posted to the server. But because the NoCaptcha js calls preventDefault on the SubmitEvent and calls form.submit() via Javascript after recaptcha has passed, the SubmitEvent loses context of the action which was clicked. This leads Silverstripe just process the request using the default action. More info here.

<input> with attribute type="submit" will not be submitted with the form when using HTMLFormElement.submit(), but it would be submitted when you do it with original HTML form submit.

UndefinedOffset commented 3 years ago

Thanks!