You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using predefined validation rules like alpha, decimal, greater_than and less_than the field can't be optional, since these rules still kick in, even if the field is empty.
Expected behavior and Suggestion
Most of the predefined rules should pass trough if the field is NULL. Then use required to check for empty fields.
There might be issues with 0 numbers / decimals and required (required does not only check NULL - empty(trim($str))) but we could prevent these in custom or more specific rules instead of defining thousands of new rules like decimal_optional.
But we can't check if the Field is NULL before applying rules, because we want to be able to validate against NULL in some rules like required or maybe custom rules. So we have to check for NULL in every rule separately.
Steps to reproduce
Set alpha as validation rule, let the field blank and try to validate. In my opinion the validation error should only occur when using alphaandrequired together.
Quickfix
As stated in the comments, use the permit_empty rule.
When using predefined validation rules like
alpha
,decimal
,greater_than
andless_than
the field can't be optional, since these rules still kick in, even if the field is empty.Expected behavior and Suggestion
Most of the predefined rules should pass trough if the field is
NULL
. Then userequired
to check for empty fields.There might be issues with 0 numbers / decimals and required (
required
does not only checkNULL
-empty(trim($str))
) but we could prevent these in custom or more specific rules instead of defining thousands of new rules likedecimal_optional
.But we can't check if the Field is
NULL
before applying rules, because we want to be able to validate againstNULL
in some rules likerequired
or maybe custom rules. So we have to check forNULL
in every rule separately.Steps to reproduce
Set
alpha
as validation rule, let the field blank and try to validate. In my opinion the validation error should only occur when usingalpha
andrequired
together.Quickfix
As stated in the comments, use the
permit_empty
rule.CodeIgniter 4 version
Released 4.0.3
Affected module(s)
Validation\{FormatRules, FileRules}
(at least)The text was updated successfully, but these errors were encountered: