I need to insert ReCaptcha in a form in my ZF application. I'm trying to follow the official documentation, but the ReCaptcha service return me always the error 'incorrect-captcha-sol'. The code I'm using:
(In the form)
// configure the captcha service
$privateKey = 'XXXXXXXXXXXXXXXXXXX';
$publicKey = 'YYYYYYYYYYYYYYYYYYYY';
$recaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey);
// create the captcha control
$captcha = new Zend_Form_Element_Captcha('captcha',
array('captcha' => 'ReCaptcha',
'captchaOptions' => array(
'captcha' => 'ReCaptcha',
'service' => $recaptcha)));
$this->addElement($captcha);
(In the controller)
$recaptcha = new Zend_Service_ReCaptcha('YYYYYYYYYYYYY', 'XXXXXXXXXXXXXXX');
$result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'),
$this->_getParam('recaptcha_response_field'));
if (!$result->isValid()) {
//ReCaptcha validation error
}
Any help please?
Why do you pull a separate element from the form to make a check? This is how I do this:
Form
Controller
View
This is quite transparent code here. When form's isValid() is executed, it validates all its elements and returns true only if each of those is valid.
An of course ensure that the keys you're using are relevant to the domain where you run this code.
Let me know if you have more questions.
I was following the quick start at the zend site, and for me the following was much quicker change from the 'Figlet' captcha.