zendframework / zend-inputfilter

InputFilter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
64 stars 50 forks source link

Empty validation message for file input when sent array for file input #184

Closed ruzann closed 4 years ago

ruzann commented 5 years ago

Let's say I have an FileInput type input field.

..,
[
                'required' => false,
                'validators' => [
                    0 => [
                        'name' => \Zend\Validator\File\UploadFile::class,
                        'options' => [],
                    ],
                    1 => [
                        'name' => \Zend\Validator\File\Size::class,
                        'options' => [
                            'max ' => '1MB',
                        ],
                    ],
                    2 => [
                        'name' => \Zend\Validator\File\MimeType::class,
                        'options' => [
                            'mimeType' => 'image/jpg, image/jpeg, image/png, image/gif, image/bmp',
                        ],
                    ],
                    3 => [
                        'name' => \Zend\Validator\File\ImageSize::class,
                        'options' => [
                            'minWidth' => 50,
                            'minHeight' => 50,
                            'maxWidth' => 2048,
                            'maxHeight' => 2048,
                        ],
                    ],
                ],
                'filters' => [],
                'name' => 'logo',
                'description' => 'logo image file',
                'field_type' => 'file',
                'type' => \Zend\InputFilter\FileInput::class,
                'continue_if_empty' => true,
            ]

And I send

logo[] = 'test'

The response should be

{

"validation_messages": {
    "logo": {
        "fileUploadFileErrorNoFile": "No file was uploaded",
        "fileSizeNotFound": "File is not readable or does not exist",
        "fileMimeTypeNotReadable": "File is not readable or does not exist",
        "fileImageSizeNotReadable": "File is not readable or does not exist"
    }
},
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Unprocessable Entity",
"status": 422,
"detail": "Failed Validation"

}

But response is this.

{

"validation_messages": {
    "logo": []
},
"type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title": "Unprocessable Entity",
"status": 422,
"detail": "Failed Validation"

}

dennybrandes commented 5 years ago

Hey, which version of zend-inputfilter are you using?

ruzann commented 5 years ago

version is 2.10.0

dennybrandes commented 5 years ago

I saw that you use continue_if_empty option. I'm not sure, if this is related: https://github.com/zendframework/zend-inputfilter/pull/26