zend_captcha always fails isValid()
- by Grant Collins
Hi,
I've got an issue with Zend_Captcha always returning false when the page is submitted and the captcha's isValid() method is being called. It's driving my nuts because this as far as I am concerned should work.
I start by declaring this at the top of the action function of the controller
$captcha = new Zend_Captcha_Image('captcha',
array(
'captcha' => array(
'name' => 'graduatesignupcaptcha',
'wordlen' => 6,
'font' => $this->config->captcha->font,
'imgDir' => $baseUrl.'/images/captcha/',
'imgUrl' => $this->config->webserver->name.'/images/captcha/',
)
)
);
$captcha->setHeight(80)
->setTimeout(300);
I do usual form validation and that all works, however it is when I come to validate that the value entered into form for the captcha it always returns false.
//next we check the captcha text to ensure that the form is a person not a script
$captchaText = $form->getElement('captchainput')->getValue();
$captchaId = $form->getElement('captchaid')->getValue();
//$captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_'.$captchaId);
$captchaArray = array(
'id' => $captchaId,
'input' => $captchaText
);
if(!$captcha->isValid($captchaArray)){
$log->log(implode(",",$captcha->getErrors()), Zend_Log::DEBUG);
$form->getElement('captchainput')->setErrors(array('messages' => 'Bad security code'));
$formFailed = true;
}
I've check to ensure that the id that I am getting and storing as a hidden element in my form match the image that is being generated but no matter what I do this always fails.
Am I missing something simple here?? Or is there a better way of dealing with this??
Thanks,