Hi,

I just started to use Zend_Form_Element_File with ZF 1.6.0RC2 release.
Adding a file form element and displaying it was no problem at all.
Unfortunately, I have problems with the validation when the file element
is not optional, i.e. not set as required.

Here is an extract of my form definition (array format):

array(
    'form' => array(
        'action'   => '/employer/edit',
        'method'   => 'post',
        'name'     => 'employer_edit',
        'enctype'  => 'multipart/form-data',
        [....]
        'elements' => array(
            'employer_id' => array(
                'type'    => 'hidden',
                        'options' => array(
                        'required' => true,
                ),
            ),
            [...]
            'employer_logo' => array(
                'type'    => 'file',
                'options' => array(
                    'label'       => 'label_employer_logo',
                    'description' => 'message_employer_logo',
                    'destination' => '/tmp/upload',
                ),
            ),
            'submit_employer_edit' => array(
                'type'    => 'submit',
                'options' => array(
                    'label' => 'action_save',
                ),
            ),
        ),
    ),
);

When I send this form then the file is not transfered to '/tmp/upload'.
When I set employer_logo to be a required field then the file is
transfered. But I do not want this field to be mandatory.

I had a closer look at Zend_Form_Element_File::isValid() and saw that
$value parameter is always NULL. So when the file element is not
required this if-control is always true and thus ending validation:

   if (!$this->isRequired() && empty($value))

Is this a bug or a feature? Did I miss anything to get Zend_Form working
for non-required file elements?

Thanks and best regards,

Ralf

Reply via email to