|
|
5 years ago | |
|---|---|---|
| .. | ||
| LICENSE.txt | 8 years ago | |
| README.md | 6 years ago | |
| RulesProvider.php | 5 years ago | |
| ValidatableInterface.php | 6 years ago | |
| Validation.php | 5 years ago | |
| ValidationRule.php | 5 years ago | |
| ValidationSet.php | 5 years ago | |
| Validator.php | 5 years ago | |
| ValidatorAwareInterface.php | 6 years ago | |
| ValidatorAwareTrait.php | 5 years ago | |
| composer.json | 8 years ago | |
The validation library in CakePHP provides features to build validators that can validate arbitrary arrays of data with ease.
Validator objects define the rules that apply to a set of fields. Validator objects contain a mapping between fields and validation sets. Creating a validator is simple:
use Cake\Validation\Validator;
$validator = new Validator();
$validator
->requirePresence('email')
->add('email', 'validFormat', [
'rule' => 'email',
'message' => 'E-mail must be valid'
])
->requirePresence('name')
->notEmpty('name', 'We need your name.')
->requirePresence('comment')
->notEmpty('comment', 'You need to give a comment.');
$errors = $validator->validate($_POST);
if (!empty($errors)) {
// display errors.
}
Please make sure you check the official documentation