Zend Framework

Zend_Form_Element_File not rendering correct error message and always return a value with getValue()

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.7.0
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Form
  • Labels:
    None

Description

There was a lot of improvement on the Zend_Form_Element_File with 1.7 release.
I still notice 2 issues with it. Here is the description :

1. The getValue() always returns something even when the element is not required et nothing is post.
2. When there are several Zend_Form_Element_File in the form, the error message always relate to the first.

Here is some real case :

This form allow the post of a video file (video), a picture (frame) and a thumb :

class My_Form_upload extends Zend_Form {
public function init() {
$this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);
$this->setMethod('post');
$element = new Zend_Form_Element_File('thumb');
$element->setLabel('Thumbnail:')
->setDestination(APPLICATION_PATH.'/tmp/data')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 5120) // limit to 5k
->addValidator('Extension', false, 'jpg') // only JPEG
->setRequired(true);
$this->addElement($element);

$element = new Zend_Form_Element_File('frame');
$element->setLabel('Frame:')
->setDestination(APPLICATION_PATH.'/tmp/data')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 307200) // limit to 300k
->addValidator('Extension', false, 'jpg') // only JPEG
->setRequired(false);
$this->addElement($element);

$element = new Zend_Form_Element_File('video');
$element->setLabel('Movie:')
->setDestination(APPLICATION_PATH.'/tmp/data')
->addValidator('Count', false, 1) // ensure only 1 file
->addValidator('Size', false, 51200000) // limit to 50M
->addValidator('Extension', false, 'flv') // only FLV
->setMaxFileSize(51512320) // Set the max upload size for all the form, so it is the sum of all the fields
->setRequired(false);
$this->addElement($element);
...

When I do a getValues() on the form and nothing was send for 'frame' and/or 'video' (which are not required, I still get "data" as value.

When post the form without 'thumb (which is required), I get an error message regarding 'video' : The file 'video' was not uploaded
When it should be : The file 'thumb' was not uploaded

Maybe I didn't understand the good way to use Zend_Form_Element_File but it still look like a bug to me.

Regards,
Olivier

Activity

Hide
Thomas Weidner added a comment -

Not reproducable

Show
Thomas Weidner added a comment - Not reproducable

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: