Dancer::Plugin::FormValidator - Easy validates user input (usually from an HTML form) based on input profile for Dancer applications.
version 1.131620
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" } } }
Provides an easy validates user input based on input profile (Data::FormValidator) keyword within your Dancer application.
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
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 }
input: (Str): Name of profile (HashRef): Data to be validated (optional) if is not present getting params implicitly output: A Data::FormValidator::Results object
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
This module is developed on Github at:
http://github.com/hobbestigrou/Dancer-Plugin-FormValidator
Feel free to fork the repo and submit pull requests
Alexis Sukrieh and Franck Cuny
Please report any bugs or feature requests in github.
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::FormValidator
Dancer Data::FormValidator Dancer::Plugin::DataFormValidator
Natal Ngétal
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.
To install Dancer::Plugin::FormValidator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::FormValidator
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::FormValidator
For more information on module installation, please visit the detailed CPAN module installation guide.