Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // Users/test.ctp
  2.  
  3. echo $this->Form->create();
  4. echo $this->Form->input('firstname');
  5. echo $this->Form->end('Test');
  6.  
  7. // UsersController.php
  8.  
  9. class UsersController extends AppController {
  10. public function test() {
  11. if ($this->request->is('post')) {
  12. $this->User->set($this->request->data);
  13. if ($this->User->validates()) {
  14. pr('no errors');
  15. } else {
  16. pr($this->User->validationErrors);
  17. }
  18. }
  19. }
  20. }
  21. // UserModel.php
  22.  
  23. class User extends AppModel {
  24.  
  25. public $validate = array(
  26. 'firstname' => array(
  27. 'between' => array(
  28. 'rule' => array('between', 3, 50),
  29. 'message' => 'Firstname must be between 3 and 50 characters long.',
  30. ),
  31. 'notEmpty' => array(
  32. 'rule' => 'notEmpty',
  33. 'message' => 'You must provide first name!'
  34. )
  35. )
  36. );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement