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