alxy / oc-captcha-plugin

Integrates Googles reCAPTCHA into October.
14 stars 7 forks source link

reCAPTCHA should not be validated if AJAX form validation fails #10

Open multiwebinc opened 5 years ago

multiwebinc commented 5 years ago

I have a form that sends an AJAX request to the server. If the form does not validate using regular Laravel validation rules, I then get a response of ["timeout-or-duplicate"] when I re-submit the form because the nonce used with the reCAPTCHA field has already been used and Google is detecting a replay event. When this happens, the only way to submit the form is to refresh the page and re-enter all of the information again. I see 3 problems here:

  1. The server should not attempt to validate the reCAPTCHA field if regular form validation fails. Only when regular validation passes, the server should validate reCAPTCHA. This way the user doesn't have to re-validate reCAPTCHA because of an unrelated field failing validation.
  2. If the reCAPTCHA validation fails, the field should be reset so that the user can verify it is not a robot again. Having to refresh the page and re-enter everything again is a huge inconvenience.
  3. A reCAPTCHA fail should not prevent regular form validation from happening. At least I'm assuming that this is what is happening because the whole response is ["timeout-or-duplicate"]. Consider appending the errors to X_OCTOBER_ERROR_FIELDS in the AJAX response.