Guest User

Untitled

a guest
Apr 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. class users_model extends app_model
  3. {
  4. public $validates = array(
  5. 'email' => array(
  6. 'required' => array(VALID_NOT_EMPTY, 'Field Required.'),
  7. 'valid' => array(VALID_EMAIL, 'Valid e-mail address required.')
  8. ),
  9. 'firstname' => array(
  10. 'required' => array(VALID_NOT_EMPTY, 'Field Required.')
  11. ),
  12. 'lastname' => array(
  13. 'required' => array(VALID_NOT_EMPTY, 'Field Required.')
  14. ),
  15. 'address' => array(
  16. 'required' => array(VALID_NOT_EMPTY, 'Field Required.')
  17. ),
  18. 'city' => array(
  19. 'required' => array(VALID_NOT_EMPTY, 'Field Required.')
  20. ),
  21. 'state' => array(
  22. 'required' => array(VALID_NOT_EMPTY, 'State is Required.'),
  23. 'valid_state' => array('valid_state', 'Please choose a state from the drop-down box.')
  24. ),
  25. 'zip' => array(
  26. 'required' => array(VALID_NOT_EMPTY, 'Zip is Required.')
  27. ),
  28. /*'homephone' => array(
  29. 'required' => array(VALID_NOT_EMPTY, 'Field Required.')
  30. ),*/
  31. 'toc_agree' => array(
  32. 'required' => array('#^1$#', 'You must agree to the terms and conditions.')
  33. )
  34. );
  35.  
  36. protected function valid_state($state)
  37. {
  38. $State_Model = new State_Model;
  39. $state = $State_Model->find('abbreviation', array('abbreviation' => $state));
  40.  
  41. if (is_array($state) && count($state))
  42. {
  43. return true;
  44. }
  45.  
  46. return false;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. #### On the controller side
  53. $user = new user_model;
  54.  
  55. if($this->post)
  56. {
  57. if($user->validate($this->post))
  58. {
  59. if($user->save($this->post))
  60. {
  61. die("user valid and saved");
  62. }
  63. else
  64. {
  65. die("save failed");
  66. }
  67. }
  68. }
Add Comment
Please, Sign In to add comment