ZendFramework - Why the results of isValid always failing?

369 Views Asked by At

My post data is from Captcha adapter is as following:

  ["ffck"] => array(2) {
    ["id"] => string(32) "661db3996f5e60e71a60671496ec71a9"
    ["input"] => string(3) "dys"
  }

My code is trying to validate now, but always failing:

  Zend_Loader::loadClass('Zend_Captcha_Image');      
  $captcha = new Zend_Captcha_Image();
  $captchaArray = array(
    'id' => $post['ffck']['id'], // valid id
    'input' =>     $post['ffck']['input'] // valid input
  );

  if ($captcha->isValid($captchaArray)) {  // FAILs!!!!
    echo "working";
  } else {
    echo "fails";
  }
  Zend_Debug::dump($post) ; // 100% valid ....

  exit;

How to fix it? Or whats causing this to fail?

2

There are 2 best solutions below

4
On BEST ANSWER

The array you pass to the CAPTCHA object should just contain the two keys, so try:

$captchaArray = $post['ffck']

instead of what you are currently doing.

But the code you've posted is not valid anyway since you never generate the CAPTCHA image. I imagine you've cut down the code sample to keep the question short, so if the above fix doesn't work please edit your example to include how and where the CAPTCHA image is generated.

0
On

Check the generated html, you should only have two inputs: name="captcha[id]" and name="captcha[input]", if you have a third one with name="captcha", then you have to remove the viewhelper from the captcha element before rendering.

Ex.:

$form->getElement('captcha')->removeDecorator("viewhelper");