invalid()
Runs a number of validators on a set of data and checks if the data is invalid
Parameters
Name | Type | Default |
---|---|---|
$data | array |
[ ] |
$rules | array |
[ ] |
$messages | array |
[ ] |
Return type
array
Examples
You can change these rules based on the type of data you want to obtain and use Kirby's validators or your own custom validators.
The syntax for the $rules
array supports the following variants:
- To use a validator without parameters, use the validator name as the array value:
['required']
- To pass additional parameters to a validator, use the validator's name as the array key, and the parameter(s) as the value.
- Scalar values can be passed directly:
['maxLength' => 20]
- You can pass multiple parameters to the validator as an array:
['between' => [10, 100]]
- To pass an array as a single parameter, use a nested array:
['in' => [['foo', 'bar']]]
- Scalar values can be passed directly:
You can also separately define a message for each validation rule:
You can find an example of invalid()
used to create pages from frontend in this recipe.