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

Add note that only file rules can be used to validate files #7969

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ Rule Parameter Description
======================= ========== ============================================= ===================================================
uploaded Yes Fails if the name of the parameter does not ``uploaded[field_name]``
match the name of any uploaded files.
Prevents form from validating if file upload
is required.

kenjis marked this conversation as resolved.
Show resolved Hide resolved
max_size Yes Fails if the uploaded file named in the ``max_size[field_name,2048]``
parameter is larger than the second
parameter in kilobytes (kb). Or if the file
Expand All @@ -992,3 +995,7 @@ is_image Yes Fails if the file cannot be determined to be
======================= ========== ============================================= ===================================================

The file validation rules apply for both single and multiple file uploads.

.. note:: Only rules specifically created for file validation (like the ones listed in the table above) can be used to validate files.
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
Copy link
Contributor

@sammyskills sammyskills Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A rule typo:

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
Therefore, adding any general rules, like ``permit_empty``, to file validation rules array or string will prevend all rules for the

from file from being processed during validation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get well "prevend all rules for the from file from being processed during validation."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Therefore, if you add any general rules, like ``permit_empy`` to file validation rules array or string,
the file validation will not work correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you set rules 'permit_empty|max_size[profile_img,1024]|mime_in[profile_img,image/jpeg]', you can uplood 3mb pdf's, and validation will pass.

Copy link
Contributor Author

@dgvirtual dgvirtual Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but I cannot believe I messed up my English that much... sorry.

Should be:

general rules, like permit_empy, to file validation rules array or string will prevent all rules for the file form field from being processed during validation (thus validating even invalid files).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permit_empty (or other general rules) checks $_POST array, and the field for the file upload does not exist, so the validation passes.
However, most rules do not permit empty, and $_POST has no field for it, so if set, the validation will fail.

I don't know how to explain it briefly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's complicated. I was also thinking about filing a bug report (it is not good that adding a stray rule disables the other rules), but now I suspect that it is more of a limitation of validation than a bug...

Copy link
Member

@kenjis kenjis Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
Therefore, adding any general rules, like ``permit_empy``, to file validation rules array or string will prevend all rules for the
from file from being processed during validation.
Rules for General Use like ``permit_empty`` do not check the uploaded file (in the ``$_FILES`` superglobal),
therefore, adding these rules to file validation rules array or string will not yield the expected results.