Skip to content

koorchik/Mojolicious-Plugin-ValidateTiny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Mojolicious::Plugin::ValidateTiny - Mojolicious Plugin

SYNOPSIS

# 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

  

DESCRIPTION

L<Mojolicious::Plugin::ValidateTiny> is a L<Validate::Tiny> support in L<Mojolicious>.

METHODS

L<Mojolicious::Plugin::ValidateTiny> inherits all methods from
L<Mojolicious::Plugin> and implements the following new ones.

register

$plugin->register;

Register plugin in L<Mojolicious> application.

HELPERS

validate

$self->validate($validate_rules);

Validate parameters with provided validator and automatically set errors.

validator_has_errors

%= if (validator_has_errors) {
    <div class="error">Please, correct the errors below.</div>
% }

Check if there are any errors.

validator_error

<%= validator_error 'username' %>

Render the appropriate error.

SEE ALSO

L<Validate::Tiny>, L<Mojolicious>, L<Mojolicious::Plugin::Validator> 

About

Mojolicious wrapper for Validate::Tiny

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages