ZF-5102: Count validator does not work correctly when setMultiFile() is used.

Issue Type: Bug Created: 2008-11-29T07:58:26.000+0000 Last Updated: 2009-01-26T11:22:28.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Rob Allen (rob) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: Attachments:


Using this code:

<pre class="highlight">
$element = new Zend_Form_Element_File('foo');
$element->setLabel('Upload an image:')
        ->addValidator('Count', false, array('min' => 2, 'max' => 3))
$form->addElement($element, 'foo');

And validating using:

<pre class="highlight">
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
    $uploadedData = $form->getValues();

If you submit the form with two of the file input elements set, then the validation fails with the error: Too less files, minimum '2' are expected but '1' are given

I suspect that if you submitted with all 4 file input elements set, then the max would fail to validate too.


Posted by Thomas Weidner (thomas) on 2008-12-05T13:51:38.000+0000

No, max validation works as expected.

The problem is not that the count validation would not work, the problem is that Zend_Form calls the validation on each element individually.

According to the Count Validator you have to validate all files at once when you are validating for a minimum value. This is due to the fact that when you validate, the validator sees that you want to have minimum 2, but only one given. It does not know if you want to call this validator again for another element or not. So this validation fails when called first.

That's the reason why this error is displayed. And I would not know how this situation could be solved.

Posted by Rob Allen (rob) on 2008-12-07T00:50:37.000+0000

From the user's point of view there is one Zend_Form_Element_File.

If this problem cannot be resolved, then the option of 'min' should be removed from the Count validator. Also, the manual should be updated to stop implying that it should work. I'm not sure that max has any benefit in any real-world use-case, so maybe Count should just be removed completely.

Posted by Thomas Weidner (thomas) on 2009-01-26T11:22:27.000+0000

Fixed with r13807 in trunk. Count validator works now as expected even with multifiles.

Have you found an issue?

See the Overview section for more details.


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

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