Search code examples
phpzend-frameworkzend-validate

ZendFramework - Why the results of isValid always failing?


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?


Solution

  • 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.