Reputation: 1189
I added A Captcha to my form
my form is created in method of my class
this is the method definition
public function generateFormAndValidate($urlcaptcha = null)
{
$form = new \Zend\Form\Form();
$formInputFilter = $form->getInputFilter();
$inputFactory = new \Zend\InputFilter\Factory();
$dirdata = './data';
//pass captcha image options
$captchaImage = new CaptchaImage( array(
'font' => $dirdata . '/fonts/arial.ttf',
'width' => 250,
'height' => 100,
'dotNoiseLevel' => 40,
'lineNoiseLevel' => 3)
);
$captchaImage->setImgDir($dirdata.'/captcha');
$captchaImage->setImgUrl($urlcaptcha);
//add captcha element...
$form->add(array(
'type' => 'Zend\Form\Element\Captcha',
'name' => 'captcha',
'options' => array(
'label' => 'Please verify you are human',
'captcha' => $captchaImage,
),
));
$formInputFilter->add ( $inputFactory->createInput ( array(
'name' => 'captcha',
// 'required' => 'true'
))
);
}
and in controller:
// ......
$form->setData($post);
if ($form->isValid()) {
}
else {
}
//....
my captcha Image showing correctly ,and captcha code is posted and I checked Session And Everything is ok
but $form->isValid
return True any time and even i put captcha input empty or use any character it returns True
anyway
i guess isValid
method not checked captcha at all .
Upvotes: 0
Views: 331
Reputation: 1623
In your Controller:
//...
$form->setData($post);
$form->setInputFilter($form->getInputFilter()); //You missed this line
if ($form->isValid()) {
// ...
Upvotes: 1