I want to write a JavaScript and php validation for reCAPTCHA
In my php I have the function below but I doesn't work. It doesn't, return an errror message if I enter the wrong reCAPTCHA
code:
function invalid($inputname,$error_message)
{
$this->js.='if (!invalid(formname.'.$inputname.',"'.$error_message.'")) return false;';
if ( isset($_POST[$inputname]) && strlen($_POST[$inputname]) - strlen(str_replace(' ','',$_POST[$inputname])) > $limit && $_POST[$inputname] != "")
{
$this -> error_message .= $error_message.'<br>';
}
}
I don't want to just echo the message I want to echo the message on top of the form like I did with my other validate using:
Can someone show me how to do it correctly in php and javascript?
Thanks
Please read the reCAPTCHA documentation . It clearly outlines the correct use of the recaptcha_check_answer()
function (part of the reCAPTCHA PHP library) to validate solutions.
This
strlen($_POST[$inputname]) - strlen(str_replace(' ','',$_POST[$inputname])) > $limit
will be false, assuming $limit is something like 6. Should be just
strlen(str_replace(' ','',$_POST[$inputname])) > $limit
Let's say the captcha is "bananas". strlen("bananas") - strlen("bananas") == 0
.
Added The JavaScript doesn't return false
at any point, so it will return undefined
if the captcha is correct, which may affect your code elsewhere (particularly if you are using === ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.