This demo show you how to use ZF2 Captcha Form Element, There are 4 adapters:
For Dump
adapter, we can setup the captcha element like the following:
$this->add([
'type' => 'Zend\Form\Element\Captcha',
'name' => 'captcha',
'options' => [
'label' => 'Please type this word BACKWARDS',
'captcha' => [
'class' => 'Dump',
'options' => [],
],
],
]);
For Figlet
adapter, we can setup the captcha element like the following:
$this->add([
'type' => 'Zend\Form\Element\Captcha',
'name' => 'captcha',
'options' => [
'label' => 'Please verify you are human.',
'captcha' => [
'class' => 'Figlet',
'options' => [
'outputWidth' => 80,
'wordLen' => 7,
],
],
],
]);
For Image
adapter, we can setup the captcha element like the following:
$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'
],
],
],
]);
By the way, you can find other examples using Zend Framework 2 in our home page :)