php - Skip validators in Zend Framework 2 Forms -
i using zend framework 2 building project. in 1 of forms have field needs validates several validators if given condition satisfied (e.g. value of form field).
is there way skip validation of field based on external condition?
you can use method setvalidationgroup
inside inputfilter
class set input fields should validated.
you example extend inputfilter
class , use setvalidationgroup
in customized setdata
method, , set group depending on presence of field in $data
.
for example this:
<?php namespace application\inputfilter; use zend\inputfilter\inputfilter; class custominputfilter extends inputfilter { /** * set data use when validating , filtering * * @param array|traversable $data * @return inputfilterinterface */ public function setdata($data) { $group = array( // custom validation group ); if(isset($data['fieldname'])){ $this->setvalidationgroup($group); } // forward default setdata method return parent::setdata($data); } }
extending class 1 option show possible. can of course setvalidationgroup
somewhere else externally without customizing inputfilter
class.
$group = array( // custom validation group ); $inputfilter->setvalidationgroup($group);
Comments
Post a Comment