Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a form with fields captcha and a submit button , the problem i am having the form submits even if the captcha is wrong

What I have tried:

function validateRecaptcha() {
    var response = grecaptcha.getResponse();
    if (response.length === 0) {
        alert("not validated");
        return true; // form will be submitted
    } else {
        alert("validated");
        return false; //form will not be submitted
    }
Posted
Updated 8-Apr-21 19:53pm
Comments
CHill60 8-Apr-21 11:10am    
What is in response?
Richard MacCutchan 8-Apr-21 11:39am    
It looks like your return values are the wrong way round.
CHill60 8-Apr-21 11:42am    
In addition to Richard's eagle-eyed observation ... aren't you supposed to validate the response with the Google API and use the result from that validation?
Richard Deeming 9-Apr-21 4:36am    
Indeed - validating the captcha on the client serves no purpose, since the bots you're trying to exclude will simply not execute your script. :)

1 solution

JavaScript
function validateRecaptcha() {
    var response = grecaptcha.getResponse();
    if (response.length === 0) {
        alert("not validated");
        return false;               // not valid then return false
    } else {
        alert("validated");
        return true;                // If valid then return true
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900