Sunday
7
September
2008

Zend_File_Transfer and isRequired

Hy fellows,

some of you have mentioned that Zend_Form_Element_File does not properly handle file uploads when the element was set as not required.

The reason was that Zend_File_Transfer checks all given input, in our case of HTTP POST the complete $_FILES array. Within this array we will find all files, of course also the prepared but not uploaded ones.

So, to get around this, we would have to ignore errors when isRequired is set to false. This was the solution of an issue which has been added by one of you. But this would lead to another problem: When you have multiple file elements, one required, and the other not required, this would not work because the elements setting isRequired to false would also negotate errors from the fileupload which is set required.

The finished and working solution acts different:
I added an new option to Zend_File_Transfer: ignoreNoFile. When it is set it will ignore all errors for the file where this option is set. Of course Zend_Form_Element_File was also changed to handle this new feature itself.

For you, as customer, there is no change in your code. The file element will handle this option in the background.
Of course, to get around of this nasty problem, you will have to use the SVN trunk or wait until 1.6.1

Enjoy it… new features are, of course, already in development and I will inform you as first one. :-)

Greetings
Thomas, I18N Team Leader, Zend Framework

Back to top