zf2 image captcha

For programming and general questions on Zend Framework

zf2 image captcha

Postby jobsfan on Tue Jan 01, 2013 4:29 am

Warning: Creating default object from empty value in E:\project\module\Admin\src\Admin\Form\AdminForm.php on line 16
my AdminForm in the moudle src/model like
Code: Select all
<?php
namespace Admin\Form;

use Zend\Form\Form;
use Zend\Captcha\AdapterInterface as CaptchaAdapter;
use Zend\Validator\ValidatorInterface;
use Zend\Captcha\Image;
use Zend\Form\Element;

class AdminForm extends Form
{
   protected $captcha;
   public function __construct()
   {
      parent::__construct('admin');
      $ths->captcha = new Image(array(
         'Expiration' => '300',
         'wordlen' => '5',
         'Height' => '50',
         'Width' => '200',
         'Font' => 'data/fonts/arial.ttf',
         'FontSize' => '24',
         'ImgDir' => 'data/images'
      ));
      $this->setAttribute('method', 'post');
      $this->add(array(
         'name' => 'account',
         'attributes' => array(
            'type' => 'text'
         ),
         'options' => array(
            'label' => 'Account'
         )
      ));
      $this->add(array(
         'name' => 'passwd',
         'attributes' => array(
            'type' => 'password'
         ),
         'options' => array(
            'label' => 'Passwd'
         )
      ));
      $this->add(array(
            'name' => 'captcha',
            'attributes' => array(
               'type' => 'captcha'
            ),
            'options' => array(
               'label' => 'Please verify you are human.',
               'captcha' => $this->captcha
            )
      ));
      $this->add(new Element\Csrf('security'));
      $this->add(array(
         'name' => 'submit',
         'attributes' => array(
            'type' => 'submit',
            'value' => 'Submit'
         )
      ));
   }
}



my related view as
Code: Select all
<div class="login">
<?php
$this->headTitle('Admin Homepage');
$form = $this->form;
$form->setAttribute('action', $this->url('admin', array('module' => 'admin','controller' => 'index','action' => 'dologin')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('account'));
echo $this->formRow($form->get('passwd'));
//echo $this->formCaptcha($form->get('captcha'));
echo $this->formElement($form->get('security'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
</div>


line 16 start from

Code: Select all
$ths->captcha = new Image(array(
         'Expiration' => '300',
         'wordlen' => '5',
         'Height' => '50',
         'Width' => '200',
         'Font' => 'data/fonts/arial.ttf',
         'FontSize' => '24',
         'ImgDir' => 'data/images'
      ));
jobsfan
 
Posts: 23
Joined: Sat Sep 08, 2012 3:15 am

Re: zf2 image captcha

Postby wout4741 on Thu Oct 17, 2013 9:03 am

$ths->captcha = new Image(array(

has to be

$this->captcha = new Image(array(

?
wout4741
 
Posts: 1
Joined: Thu Oct 17, 2013 9:02 am


Return to Zend Framework

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests