ZF-12115: Zend_Validate_File_Count fails on Zend_Form_Element_File when isValid called more than once & a new file destination is set

Issue Type: Bug Created: 2012-03-22T11:27:33.000+0000 Last Updated: 2012-03-22T11:27:33.000+0000 Status: Open Fix version(s): Reporter: bullfrogblues (gerardroche) Assignee: Thomas Weidner (thomas) Tags: - Zend_File_Transfer

  • Zend_Form
  • Zend_Validate
  • Zend_Validate_File_Count,

Related issues: Attachments:


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:

<pre class="highlight">
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();

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?


No comments to display

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.