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

Issue Type: Bug Created: 2011-09-22T14:55:47.000+0000 Last Updated: 2012-07-30T10:00:07.000+0000 Status: Closed Fix version(s): Reporter: Arun Vasudevan Nair (aruntechguy) Assignee: Frank Brückner (frosch) Tags: - Zend_Form

  • zend_form

Related issues: Attachments:


<pre class="highlight">

$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"


Posted by Adam Lundrigan (adamlundrigan) on 2011-09-23T01:39:43.000+0000

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

Posted by Thomas Weidner (thomas) on 2011-10-28T04:49:24.000+0000

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.

Posted by Frank Brückner (frosch) on 2012-07-30T09:58:39.000+0000

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

<pre class="highlight">
        'label'    => 'Photo',
        'required' => true,
    'Please choose an image file to upload',

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.