ZF-4780: Form_Element_File->addValidator('Extension', true, 'txt') doesn't work
Description
$subForm->createElement('file', 'txt')
->setDestination($options['tmp'])
->addFilter('Rename', $options['tmp'] . '/' . md5(microtime(true)))
->setRequired(true)
->addValidator('Count', false, 1) // ensure only 1 file
->setMaxFileSize(10 * 1024 * 1024) // limit to 10M
//->addValidator('FilesSize', true, '1MB')
->addValidator('Extension', true, 'txt'), // only JPEG, PNG, and GIFs
Every upload has error ($form->getErrors('txt')) like this: "The file 'readme.txt' was not found"
'FilesSize' Validator seems to doesn't work too :P
If I uncomment above validator, I've got: * One or more files can not be read * The file 'readme.txt' was not found
Why I've got 2 errors, while I've true in $breakChainOnFailure? Why I've errros? :)
Comments
Posted by Thomas Weidner (thomas) on 2008-11-02T13:44:58.000+0000
Please do not double enter issues.
Please try out trunk r12267 and not 1.7pre when you have issues. There has been much changed in the last 4 weeks.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T13:49:52.000+0000
As I said in other issue, I've using newest trunk. Sorry for mistake in bug description.
Posted by Thomas Weidner (thomas) on 2008-11-02T14:08:15.000+0000
So which does not work... the header declares Extension does not work. But in your description you declare that FilesSize valdiator does not work as also in your code example.
Which validator does not work ? Please give the $_FILES array after submittion.
Related to breakchain... it does only break the chain for the single file element, but not for other elements. So when you validate two elements by calling $form->isValid() you will get one error for each element.
And please give the code you use afterwards for validation and retrievment of the files.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T14:24:35.000+0000
Doesn't work 'FilesSize' and 'Extension' too. {quote} Related to breakchain... it does only break the chain for the single file element, but not for other elements. So when you validate two elements by calling $form->isValid() you will get one error for each element. {quote} This is for one element... {quote} * One or more files can not be read * The file 'readme.txt' was not found {quote} validation code, only:
Dumps after validation code $_FILES:
form->getErrors()
$form->getValues()
Posted by Thomas Weidner (thomas) on 2008-11-02T14:36:39.000+0000
There is something wrong...
Your first code creates a file element named "txt". But your $_FILES array declares that the elements are named "file1" and "file2".
This does not match... eighter the first code you gave is wrong, or the $_FILES array is not from the above code.
Please give the correct code and $_FILES array for investigation.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T14:51:32.000+0000
Huh, what difference? I've changed form element names... Full code, perfect simply:
output of var_dump:
Posted by Thomas Weidner (thomas) on 2008-11-02T14:56:14.000+0000
For example the difference that in your code you only declare one single file element and in your returned $_FILES array there are 2 file elements ?
Posted by Thomas Weidner (thomas) on 2008-11-02T15:18:39.000+0000
So there is one problem with your code...
You can not getPost() and then validate the elements when there has nothing be posted. According to manual you have previously to check with isPost().
This has nothing to do with the file element but with generic form handling. I am no forms expert as this is not my component but even I can say that validation on empty elements will ALWAYS FAIL.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T15:19:27.000+0000
But it doesn't matter. Additionaly I've got Notice, when I trying to get $form->getValues(); in my form (see code below) without submit data (just GET).
I've form, deeply inserted in my application and I should copy you half of my files. So to simpliest this, I change some of fields to copy you point. Here you are 2 files, but bug is same, and there isn't difference, that you add 1, 2 or 50 files.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T15:27:11.000+0000
{quote}You can not getPost() and then validate the elements when there has nothing be posted. According to manual you have previously to check with isPost().{quote} I don't understand. you mean
as what?
? Is it not the same?
Posted by Thomas Weidner (thomas) on 2008-11-02T15:28:36.000+0000
When there were no difference I would not have asked... Still you can not validating non existing input... this will always fail as I already wrote.
Posted by Adam Kusmierz (raistlin) on 2008-11-02T15:36:42.000+0000
``` empty($postValues) - ok, this could be not the same as $this->getRequest()->isPost(), but in this example is.
And, as you know, if first element in tuple, ie. a & b is false, so php leave it (see Boolean algebra), even NOT check second element. I can't find differences, or I'm blind. Could you tell me, where it is?
PS Code above doesn't work too. It has same dump output as main.
Posted by Thomas Weidner (thomas) on 2008-11-03T13:07:48.000+0000
Posted by Adam Kusmierz (raistlin) on 2008-11-03T13:27:28.000+0000
It works both with newest trunk.
Posted by Thomas Weidner (thomas) on 2008-11-03T13:36:46.000+0000
Fixed within trunk >r12272
Posted by Wil Sinclair (wil) on 2008-11-13T14:10:08.000+0000
Changing issues in preparation for the 1.7.0 release.