ZF-11763: Zend_Form_Element_File addErrorMessage is set, but rendering as File 'element name' was not uploaded



$fileDecorator = array(
    array(array('data' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr'))

$photo = new Zend_Form_Element_File("photo");
$photo->setLabel("Upload Photo")
    ->addErrorMessage('Please choose an image file to upload')

after validation, error message is showing up as "File 'photo' was not uploaded"


{{addErrorMessage}} doesn't override error messages provided by the element, it just adds additional messages to the stack.

I haven't tried it myself recently, but I believe you will have to set up your own instance of {{Zend_Validate_File_Upload}}, override the appropriate error message(s) there, and then inject that into {{Zend_Form_Element_File}} via method {{setValidators}}

I would like to check this myself.

First I am not your opinion that you must override an file validator to set messages. Second you can't override the upload validator as it is an fixed validator of the file element. Without it no upload would work.

Simple solution: Don't use the custom error messages ({{addErrorMessage}}). Use the validator and the „setMessage“ method:

        'label'    => 'Photo',
        'required' => true,
    'Please choose an image file to upload',