Welcome Guest, Not a member yet? Register   Sign In
How rules works?

please explain how its works if_exist?
What difference permit_empty?

(This post was last modified: 08-25-2023, 01:46 AM by sammyskills.)

From the docs,

Quote:if_exists: If this rule is present, validation will check the field only when the field key exists in the data to validate.

More explanation:
Validation will only check the field when the field key is present in the request data to validate. For example, you set the rule on a field like so:
PHP Code:
$rule = ['username' => "if_exists|numeric"]; 
If you submit a form that doesn't contain the input/field name of username, validation will not check that field, irrespective of the rules that follow, in this case, numeric. But if your form contains the input/field name, then validation will check for other in that same field.

Quote:permit_empty: Allows the field to receive an empty array, empty string, null or false.

More explanation:
Validation will allow a field to accept an empty value, irrespective of the associated rules. For example, you set the rule on a field like so:
PHP Code:
$rule = ['username' => "permit_empty|numeric"]; 
Your form with input/field name of username can successfully pass validation checks if the field does not contain any value.

Theme © iAndrew 2016 - Forum software by © MyBB