php - Validator not working in Zend Framework 2 -


the validator in zend framework 2 not working. can see required=>true works , shows me error if pass empty string. min , max length validations not working , $form->isvalid() return true. appreciated. i'm following tutorial on zend website. http://framework.zend.com/manual/2.3/en/user-guide/forms-and-actions.html

<?php  namespace adminauthentication\model;  use zend\inputfilter\inputfilter; use zend\inputfilter\inputfilterawareinterface; use zend\inputfilter\inputfilterinterface; use zend\inputfilter\factory inputfactory;  class login implements inputfilterawareinterface{     public $username;     public $password;      protected $inputfilter;      public function exchangearray($data){         $this->username = isset($data['username']) ? $data['username'] : null;         $this->password = isset($data['password']) ? $data['password'] : null;     }      public function setinputfilter(inputfilterinterface $inputfilter){         throw new \exception("not used!");     }      public function getinputfilter(){          if( ! $this->inputfilter ){              $inputfilter = new inputfilter();             $factory = new inputfactory();              $inputfilter->add($factory->createinput(array(                 'name' => 'username',                 'required' => true,                 'filters' => array(                     array('name' => 'striptags'),                     array('name' => 'stringtrim' ),                 ),                 'validators' => array(                     array('name' => 'stringlength',                         'encoding' => 'utf-8',                         'min' => 5,                         'max' => 35                      )                  )             )));              $inputfilter->add($factory->createinput(array(                 'name' => 'password',                 'required' => true,                 'filters' => array(                     array('name' => 'striptags'),                     array('name' => 'stringtrim' ),                 ),                 'validators' => array(                     array('name' => 'stringlength',                         'encoding' => 'utf-8',                         'min' => 5                      )                  )             )));              $this->inputfilter = $inputfilter;          }         return $this->inputfilter;     }  }  

i think missed in documentation tutorial. code wrong.

you have :

'validators' => array(                 array('name' => 'stringlength',                     'encoding' => 'utf-8',                     'min' => 5,                     'max' => 35                  )              ) 

you should have :

'validators' => array (                     array (                             'name' => 'stringlength',                             'options' => array (//<-----options array here                                     'encoding' => 'utf-8',                                     'min' => 1,                                     'max' => 100                              )                      )              )  

the min, max , encoding should in options array.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -