NAME
Dancer::Plugin::FormValidator - Easy validates user input (usually from an HTML form) based on input profile for Dancer applications.
VERSION
version 1.131620
SYNOPSIS
use Dancer;
use Dancer::Plugin::FormValidator;
get '/contact/form' => sub {
my $input_hash = {
Name => $params->{name},
Subject => $params->{subject},
Body => $params->{body},
};
my $error = form_validator_error( 'profile_contact', $input_hash );
if ( ! $error ) {
#the user provided complete and validates
# data it's cool to proceed
}
};
dance;
Example of profile file:
{
profile_contact => {
'required' => [ qw(
Name Subject Body
)],
msgs => {
missing => 'Not Here',
}
},
}
Example with yml format:
profile_contact:
required:
- name
- subject
- body
msgs:
missing: Not here
Example with json format:
{
"profile_contact": {
"required": [
"name",
"subject",
"body"
],
"msgs": {
"missing": "Not here"
}
}
}
DESCRIPTION
Provides an easy validates user input based on input profile (Data::FormValidator) keyword within your Dancer application.
METHODS
form_validator_error
form_validator_error('profile_name');
or
form_validator_error('profile_name', $input);
Validate forms.
input: (Str): Name of profile
(HashRef): Data to be validated (optional) if is not present
getting params implicitly
output: (HashRef): Field was missing or invalid or return 0 if all field is
valid
dfv
if ( my $results = dfv('profile_name') ) {
Do some stuff
}
else {
Report some failure
}
or
if ( my $results = dfv ('profile_name', $input) ) {
Do some stuff
}
else {
Report some failure
}
Validate forms.
input: (Str): Name of profile
(HashRef): Data to be validated (optional) if is not present
getting params implicitly
output: A Data::FormValidator::Results object
CONFIGURATION
plugins:
FormValidator:
profile_file: 'profile.pl'
halt: 0
msg:
single: 'Missing field'
several: 'Missing fields'
For the profile file it's possible to use json, yml or pl format. The halt option is only available with form_validator_error function, if you don't use halt option, a hashref is return with name of fields for the key and reason of the value use msgs profile, if you missing specified a msgs in a profil, msg single is use. The profile file it begins at the application root. The default of profile_file name is profile.yml
CONTRIBUTING
This module is developed on Github at:
http://github.com/hobbestigrou/Dancer-Plugin-FormValidator
Feel free to fork the repo and submit pull requests
ACKNOWLEDGEMENTS
Alexis Sukrieh and Franck Cuny
BUGS
Please report any bugs or feature requests in github.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::FormValidator
SEE ALSO
Dancer Data::FormValidator Dancer::Plugin::DataFormValidator
AUTHOR
Natal Ngétal
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Natal Ngétal.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.