Mojolicious::Plugin::ValidateTiny - Mojolicious Plugin
# Mojolicious
$self->plugin('ValidateTiny');
# Mojolicious::Lite
plugin 'ValidateTiny';
sub action {
my $self = shift;
my $validate_rules = {};
if ( my $params = $self->validate($validate_rules) ) {
# all $params are validated and filters are applyed
... do you action ...
} else {
$self->render(status => '403', text => 'FORBIDDEN');
}
}
__DATA__
@@ user.html.ep
%= if (validator_has_errors) {
<div class="error">Please, correct the errors below.</div>
% }
%= form_for 'user' => begin
<label for="username">Username</label><br />
<%= input_tag 'username' %><br />
<%= validator_error 'username' %><br />
<%= submit_button %>
% end
L<Mojolicious::Plugin::ValidateTiny> is a L<Validate::Tiny> support in L<Mojolicious>.
L<Mojolicious::Plugin::ValidateTiny> inherits all methods from
L<Mojolicious::Plugin> and implements the following new ones.
$plugin->register;
Register plugin in L<Mojolicious> application.
$self->validate($validate_rules);
Validate parameters with provided validator and automatically set errors.
%= if (validator_has_errors) {
<div class="error">Please, correct the errors below.</div>
% }
Check if there are any errors.
<%= validator_error 'username' %>
Render the appropriate error.
L<Validate::Tiny>, L<Mojolicious>, L<Mojolicious::Plugin::Validator>