php - How to add a new validator to field into collection (fieldset) -


i add new validator (using inputfilter) collection.

the current code follows:

my code form:

namespace eventyevent\form;  use zend\form\element; use zend\form\form; use zend\inputfilter\inputfilter; use zend\stdlib\hydrator\classmethods classmethodshydrator;  class eventeditbasicform extends form {  public function __construct(){     parent::__construct();      $this   ->setname('event')             ->setattribute('method', 'post')             ->setattribute("accept-charset", "utf-8")             ->sethydrator(new classmethodshydrator(false))             ->setinputfilter(new inputfilter());   // date     $this->add(array(         'type' => 'zend\form\element\collection',         'name' => 'dates',         'options' => array(             'label' => "dates of event",             'count' => 1,             'target_element' => array(                 'type' => 'eventyevent\form\basic\datefieldset'             )         )     )); } 

my code fieldset:

namespace eventyevent\form\basic;  use eventyevent\entity\eventdates; use zend\form\fieldset; use zend\inputfilter\inputfilterproviderinterface; use zend\stdlib\hydrator\classmethods classmethodshydrator;  class datefieldset extends fieldset implements inputfilterproviderinterface{  public function __construct() {     parent::__construct('eventdates');     $this->sethydrator(new classmethodshydrator(false))          ->setobject(new eventdates());      // date start     $this->add(array(         'name' => 'datestart',         'attributes' => array(             'required' => 'required',             'type'=>'text',         ),         'options'=>array(             'label'=>"date start",         )     ));      // date end     $this->add(array(         'name' => 'dateend',         'attributes' => array(             'required' => 'required',             'type'=>'text',         ),         'options'=>array(             'label'=>"date end",         )     ));    }  /**  * @return array  */ public function getinputfilterspecification() {     return array(         'datestart' => array(             'required' => true,             'validators' => array(                 array(                     'name' => 'date',                     'options' => array(                         'format' => 'd f y - h:i'                     ),                 ),             ),         ),         'dateend' => array(             'required' => true,             'validators' => array(                 array(                     'name' => 'date',                     'options' => array(                         'format' => 'd f y - h:i'                     ),                 ),             ),         ),     ); } } 

i want add validator date later before validation in controller, can i? tips, corrections or suggestions?

one way validator chain fieldset field forms input filter , attach own validator chain.

assuming have imaginary dateislatervalidator attach, here's example add validator dateend field.

$form = new eventeditbasicform;  $datevalidators = $form->getinputfilter()->get('dates')                                          ->get('dateend')                                          ->getvalidatorchain();  $datelatervalidator = new dateislatervalidator;  $datevalidators->attach($datelatervalidator); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -