ZF-5878: Zend_Form_Element_File does not register errors nor display them
Description
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.
Example:
<?php
// 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
Comments
Posted by Remy Damour (remy215) on 2009-02-24T11:27:05.000+0000
``` does not work either (but works on non-file items)
Posted by Thomas Weidner (thomas) on 2009-02-24T23:26:58.000+0000
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.
Posted by Remy Damour (remy215) on 2009-02-25T00:52:07.000+0000
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:
Here is /application/views/scripts/index/index.phtml:
Actual Result:
Upload a filePosted by Thomas Weidner (thomas) on 2009-02-25T02:02:49.000+0000
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 ...at the first validator ? What when you delete this validator ? ...at 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.
Posted by Thomas Weidner (thomas) on 2009-02-25T03:39:07.000+0000
Changed type from bug to improvement. Will be reviewed internally.
Posted by Remy Damour (remy215) on 2009-02-25T05:25:41.000+0000
If addError method is not used, it may be interesting for it to throw an exception. Thanks for the explanation anyway.
Posted by Thomas Weidner (thomas) on 2009-03-05T23:02:34.000+0000
Integrated with r14233