ZF-5878: Zend_Form_Element_File does not register errors nor display them


When I add an error to a Zend_Form_Element_File element: - -error is not registered- error is registered, it is not returned by ::getErrors() but returned by ::getErrorMessages() - error is not outputed when element is rendered whereas same piece of code on non-file element (text / textarea / checkbox ...) works perfectly.


// note: $form points to a Zend_Form instance and 'attachment' is a Zend_Form_Element_File object
$form->attachment->addError('An error occured');
echo $form->attachment; 

Actual result:

Attach file

Expected result:

Attach file
An error occured


``` does not work either (but works on non-file items)

Please give a complete example of your element and form creation/validation. Because errors are rendered and tested in the testbed and displayed in my browser.

I've created a very simple controller action that does only one thing, output a form with an error attached on File element.

Here is /application/controllers/IndexController.php:

require_once 'Zend/Controller/Action.php';

 * Default controller, used for redirections only
class IndexController extends Zend_Controller_Action
     * Show upload form
    public function indexAction()
        require_once 'Zend/Form.php';
        $form = new Zend_Form();
        $attachment = $form->createElement('file', 'attachment')->setLabel('Upload a file')->addError('An error occured');
        $this->view->form = $form;

Here is /application/views/scripts/index/index.phtml:

<?php echo $this->form->render(); 

Actual Result:

Upload a file

I see... To describe this:

The file element is based on the file transfer adapter. So also the error is thrown from the adapter.

When you create a new error type with addError, this is not supported by files because the adapter would not know where he should attach it. Files themself do not have a error, they are working with validators.

Also, when you add a new errortype where should it be attached the first validator ? What when you delete this validator ? all validators ? Same error would be displayed multiple times ? ...and when this works, only displaying the attached error ? Or also the file errors ?

I would solve this different, at the time you validate / receive the file as shown in several examples.

Btw: renderErrors() works by me, but displays as described previously only file errors.

Changed type from bug to improvement. Will be reviewed internally.

If addError method is not used, it may be interesting for it to throw an exception. Thanks for the explanation anyway.

Integrated with r14233