Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2.  
  3. // sample controller
  4. class _sample extends framework
  5. {
  6. // sample action
  7. function contact()
  8. {
  9. if ($this->Is->Post() === true)
  10. {
  11. $errors = array();
  12.  
  13. if ($this->Is->Set($_POST['name']) === false)
  14. {
  15. $errors['name'] = 'Please fill in your name.';
  16. }
  17.  
  18. if (($this->Is->Email($_POST['email']) === false) || ($this->Is->Set($_POST['email']) === false))
  19. {
  20. $errors['email'] = 'Please fill in your email address.';
  21. }
  22.  
  23. if (($this->Is->Phone($_POST['contact']) === false) && ($this->Is->Mobile($_POST['contact']) === false))
  24. {
  25. $errors['contact'] = 'Please fill in your phone (or cell phone) number.';
  26. }
  27.  
  28. if ($this->Is->Set($_POST['message']) === false)
  29. {
  30. $errors['message'] = 'Please type a message';
  31. }
  32.  
  33. // no errors, it's valid!
  34. if (empty($errors) === true)
  35. {
  36. // do stuff and redirect to "success" / "thank you" page
  37. }
  38.  
  39. // load the form view, and let it display the errors
  40. // automatically prefill fields with $_POST values
  41. else
  42. {
  43. $this->View('contact_form', $errors);
  44. }
  45. }
  46.  
  47. // load the form view for the first time
  48. else
  49. {
  50. $this->View('contact_form');
  51. }
  52. }
  53. }
  54.  
  55. ?>
Add Comment
Please, Sign In to add comment