zend framework - ZF 2.4 File Validator Required False Doesn't Work -
today updated zf 2.4 use float validator unfortunately realized file upload form field gives unexpected error messages.
here form object
$this->add([ 'name' => 'profileimage', 'type' => '\zend\form\element\file', 'attributes' => [ 'id' => 'profileimage', 'class' => 'styled', ], ] );
and here validator
$inputfilter->add([ 'name' => 'profileimage', 'required' => false, 'allow_empty' => true, 'priority' => 300, 'filters' => [ ['name' => 'striptags'], ['name' => 'stringtrim'], ], 'validators' => [ [ 'name' => '\zend\validator\file\isimage', ], [ 'name' => '\zend\validator\file\uploadfile', ], [ 'name' => '\zend\validator\file\imagesize', 'options' => [ 'minwidth' => 300, 'minheight' => 300, ] ], [ 'name' => '\zend\validator\file\size', 'options' => [ 'max' => '20mb', ] ], ] ]);
as see image upload field not required , may empty. in form these errors:
array (size=1) 'profileimage' => array (size=4) 'fileisimagenotreadable' => string 'file not readable or not exist' (length=38) 'fileuploadfileerrornofile' => string 'file not uploaded' (length=21) 'fileimagesizenotreadable' => string 'file not readable or not exist' (length=38) 'filesizenotfound' => string 'file not readable or not exist' (length=38)
how can handle issue? need field optional.
change filter
$inputfilter->add([ 'name' => 'profileimage', 'type' => '\zend\inputfilter\fileinput', 'required' => false, 'allow_empty' => true, 'priority' => 300, 'filters' => [ ['name' => 'striptags'], ['name' => 'stringtrim'], ], 'validators' => [ [ 'name' => '\zend\validator\file\isimage', ], [ 'name' => '\zend\validator\file\uploadfile', ], [ 'name' => '\zend\validator\file\imagesize', 'options' => [ 'minwidth' => 300, 'minheight' => 300, ] ], [ 'name' => '\zend\validator\file\size', 'options' => [ 'max' => '20mb', ] ], ] ]);
read here: http://framework.zend.com/manual/current/en/modules/zend.input-filter.file-input.html
Comments
Post a Comment