Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files as optional in validation rules #3619

Closed
luispastendev opened this issue Sep 7, 2020 · 3 comments
Closed

Files as optional in validation rules #3619

luispastendev opened this issue Sep 7, 2020 · 3 comments

Comments

@luispastendev
Copy link

luispastendev commented Sep 7, 2020

Applying the permit_empty rule within the validation of a file does not work correctly as it completely ignores the validation if the user uploads a file

$rules['fotos.*'] = [
    'rules' => 'permit_empty|uploaded[field]|max_size[field,500]|is_image[field]',
];

Another method that could also be useful is to restrict the number of files that a user can upload in the case of using multiple files max_files[field, 3] or a minimum of min_files[field, 2]

grettings

@nyufeng
Copy link
Contributor

nyufeng commented Sep 8, 2020

Since the value of a file upload HTML field doesn’t exist.
So, 'permit_empty' always return true.

@crustamet
Copy link
Contributor

this is not a bug some validations are for $_POST, and some are for $_FILES don`t use them together.

just dont use the uploaded[field] rule if you dont want it to be required

@michalsn
Copy link
Member

michalsn commented Sep 8, 2020

In the user guide, we have separate sections for file uploads related rules.

The idea with the validation rule for max and min number of files sounds good. PRs are welcomed, as always.

@michalsn michalsn closed this as completed Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants