Reputation: 2551
Cake3.6:
I am validating a form field which allows multiple files to be uploaded:
$this->Form->input('listing_images. ', ['type' => 'file', 'multiple' => 'multiple']);
I have a custom validation provider which correctly validates the multiple images:
$validator ->add('listing_images', 'listing_images', [
'rule' => [
'dimensions', [
'min' => ['w' => 100, 'h' => 100],
'max' => ['w' => 1600, 'h' => 1600]
]
],
'message' => 'Maximum image size is 1600 x 1600 pixels',
'provider' => 'custom'
]);
The problem is that when validation fails the validation error does not appear below the field. If make the file upload single file only and name is 'listing_images' the validation error does appear.
Why does it not work for multiple?
Upvotes: 0
Views: 381
Reputation: 60463
While it may work partially, the trailing dot syntax that you are using isn't supported (and the trailing space only makes things worse), the form helper will not be able to find the field based on that name.
You can use the name
option to specify a name with trailing brackets as required for a multiple file upload HTML input, while passing the regular field name that the form helper understands:
echo $this->Form->control('listing_images', [
'type' => 'file',
'name' => 'listing_images[]',
'multiple' => 'multiple',
]);
Upvotes: 1