O
O
Oklick2016-08-22 21:34:50
Zend Framework
Oklick, 2016-08-22 21:34:50

Why can't I add Captcha to the form?

Good day.
While developing a site on zf2, I encountered such a problem: when adding captcha to the form, an error occurs:

Fatal error: Class 'Zend\Captcha\Factory' not found in C:\xampp\htdocs\td.ru\vendor\zendframework\zend-form\src\Element\Captcha.php on line 53

What surprises me is that judging by the error text, the code is not correct in zf2 itself, but I highly doubt it.
Please tell me what is the reason and how to fix this error.
Here is the code for the form itself:
namespace Users\Form;

use Zend\Form\Element;
use Zend\Form\Form;
use Zend\Captcha\AdapterInterface;

class RegisterForm extends Form {

    protected $captcha;

    public function __construct($name = null) {

        parent::__construct('Register');
        $this->setAttribute('method', 'post');
        $this->setAttribute('enctype', 'multipart/form-data');

        $this->add([
            'type' => 'Zend\Form\Element\Captcha',
            'name' => 'captcha',
            'options' => [
                'label' => 'Please verify you are human.',
                'captcha' => [
                    'class' => 'Image',
                    'options' => [
                        'font' => __DIR__ . '/../assets/fonts/arial.ttf',
                        'width' => 200,
                        'height' => 100,
                        'dotNoiseLevel' => 40,
                        'lineNoiseLevel' => 3,
                        'imgDir' => '/path/to/image/captcha/will/be/generated'
                    ],
                ],
            ],
        ]);
..................................

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-08-22
@Oklick

You need to install zend-captcha , which is not in the zend-form dependency list but is in the suggest list:
$ composer require zendframework/zend-captcha

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question