Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. sub startup {
  2. 7
  3. 8 my $self = shift;
  4. 9
  5. 10 ## Secrety stuff
  6. 11 $self->secrets(['I love chicken']);
  7. 12
  8. 13 ## Documentation browser under "/perldoc"
  9. 14 $self->plugin('PODRenderer');
  10. 15
  11. 16 ## Router
  12. 17 my $r = $self->routes;
  13. 18
  14. 19 ## Normal routes to controller
  15. 20 $r->get('/')->to('main#index');
  16. 21 $r->get('/solutions')->to('main#solutions');
  17. 22 $r->get('/resources')->to('main#resources');
  18. 23 $r->get('/about')->to('main#about');
  19. 24 $r->get('/contact')->to('main#contact');
  20. 25 $r->post('/contact')->to('main#post_contact');
  21. 26
  22. 27 my $confirmation $r->under('/contact')->to('main#validated');
  23. 28 $confirmation->get('/confirmation')->to('main#confirmation');
  24. 29
  25. 30 }
  26.  
  27. Main.pm
  28.  
  29. 52 sub post_contact {
  30. 53
  31. 54 my $self = shift;
  32. 55 my $params = $self->req->params->to_hash;
  33. 56 my $validation = $self->validation;
  34. 57
  35. 58 return $self->render unless $validation->has_data;
  36. 59
  37. 60 ## Validate parameters
  38. 61 $validation->required('email')->size(1,100)->like(qr/^(\w+|\w+\.\w+)@\w+\.\w+$/);
  39. 62
  40. 63 ## Re-present the form if validation fails and store errors
  41. 64 if ($validation->has_error) {
  42. 65
  43. 66 for my $failure (@{$validation->failed}) {
  44. 67
  45. 68 $self->flash($failure => $validation->param("$failure"));
  46. 69
  47. 70 }
  48. 71
  49. 72 return $self->render(template => '/main/contact');
  50. 73
  51. 74 ## Else send email and redirect to confirmation page.
  52. 75 } else {
  53. 76
  54. 77 ## Create email object here and construct email...
  55. 78 $self->redirect_to('/main/confirmation');
  56. 79
  57. 80 }
  58. 81
  59. 82 }
  60. 83
  61. 84 sub validated {
  62. 85
  63. 86 return 1;
  64. 87
  65. 88 }
  66. 89 sub confirmation {
  67. 90
  68. 91 shift->render(template => '/main/confirmation');
  69. 92 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement