input

Custom Zend Validator error messages

The Zend Validator error messages are not the most helpful. Considor the below code for creating a file input:

$this->addElement('file', 'signature', array(
    'validators' => array(
        array('Size', false, 20480), //20k
        array('Extension', false, 'png'),
    ),
    'required' => false,
    'label' => 'Signature',
    'destination' => SIG_PATH,
));

For instance, on the above file input, if you attempt to upload something that is not a PNG file (i.e. photo.JPG, the message will be:

File 'photo.JPG' has a false extension

That’s not very user friendly as it doesn’t give the user any indication of what is an “allowed” file type.

Continue reading