Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Cake\Validation\Validator;
- ...
- $validator = new Validator();
- $validator
- ->validatePresence('email')
- ->add('email', 'validFormat', [
- 'rule' => 'email',
- 'message' => 'E-mail must be valid'
- ])
- ->validatePresence('name')
- ->notEmpty('name', 'We need your name.')
- ->validatePresence('comment')
- ->notEmpty('comment', 'You need to give a comment.');
- $errors = $validator->errors($this->request->data());
- if (!empty($errors)) {
- // Send an email.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement