Showing posts with label reCAPTCHA. Show all posts
Showing posts with label reCAPTCHA. Show all posts

Monday, June 4, 2018

why form is submitting without validating recaptcha


Cant get google recaptcha v2 to prevent form submission.


Step 1 

Put a js function in your form submit to validate the re-captcha:

<form action="/sign-visitors-log/" method="post" id="VisitorsLogForm" onsubmit="return validateRecaptcha();">

Step 2 : Then some js to stop the form submit if the user didn't tick the check box:

function validateRecaptcha() {
    var response = grecaptcha.getResponse();
    if (response.length === 0) {
        alert("not validated");
        return false;
    } else {
        alert("validated");
        return true;
    }
}