Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. use Cake\Validation\Validator;
  2.  
  3. ...
  4.  
  5. $validator = new Validator();
  6. $validator
  7. ->validatePresence('email')
  8. ->add('email', 'validFormat', [
  9. 'rule' => 'email',
  10. 'message' => 'E-mail must be valid'
  11. ])
  12. ->validatePresence('name')
  13. ->notEmpty('name', 'We need your name.')
  14. ->validatePresence('comment')
  15. ->notEmpty('comment', 'You need to give a comment.');
  16.  
  17. $errors = $validator->errors($this->request->data());
  18. if (!empty($errors)) {
  19. // Send an email.
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement