Reputation: 11179
Im working with a php form validation, which involves reCAPTCHA as well. Once the form is submitted, I validate the form fields, and store the error messages like
if( !$this-> valid_username($username) ){
$this->error = "username is invalid <br />";
}
and similarly other fields.
Now, How can I access the $response->is_valid
in my validation class so that I can display the captcha error sth like
if( !$response->is_valid ){
$this->error .= "Invalid captcha. <br />";
}
The idea is to display all fields errors at once. I hope my question is clear, I'd appriciate any help.
Upvotes: 0
Views: 284
Reputation: 4992
I'm not exacly sure what you mean but I guess you need this: http://code.google.com/intl/nl-NL/apis/recaptcha/docs/php.html
first include the usual reCAPTCHA library like this:
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
Then you can check the result like you mentioned above:
if (!$resp->is_valid) {
$this->error .= "Invalid captcha. <br />";
}
Upvotes: 1