ZF-12115: Zend_Validate_File_Count fails on Zend_Form_Element_File when isValid called more than once & a new file destination is set
Description
Zend_Validate_File_Count fails if you set a new file destination after isValid is called, and then call isValid again.
An example will better illustrate:
define('UPLOADS_PATH', '/path/to/uploads');
class Bug_Form_FileCountValidator {
public function init() {
$this->addElement('file', 'uploadElement', array(
'label' => 'Label text',
'valueDisabled' => true,
'validators' => array(
array('Count', true, array('max' => 1))
)
));
// ...
}
}
$form = new Bug_Form_FileCountValidator();
$form->uploadElement->setDestination(UPLOADS_PATH);
if ($form->isValid($_POST)) { // A
// set a new destination
$form->uploadElement->setDestination(UPLOAD_PATH . '/newpath');
$uploadElement->receive(); // B
}
- The validation error message we get is: "Too many files, maximum '1' are allowed but '2' are given"
- isValid is called twice on: A & B.
A quick look at Zend_Validate_File_Count and you can see that by setting a new destination after isValid is called, it causes the file count validator to add another file reference to its count when isValid is called again with a new destination. However, two files don't actually exist, we have simply changed the destination of the file that the file count validator already knows about.
I hope that makes sense?
Comments
No comments to display