| FormValidator::Lite - lightweight form validation library |
FormValidator::Lite - lightweight form validation library
use FormValidator::Lite;
FormValidator::Lite->load_constraints(qw/Japanese/);
my $q = CGI->new();
my $validator = FormValidator::Lite->new($q);
my $res = $validator->check(
name => [qw/NOT_NULL/],
name_kana => [qw/NOT_NULL KATAKANA/],
{mails => [qw/mail1 mail2/]} => ['DUPLICATION'],
);
if ( ..... return_true_when_if_error() ..... ) {
$validator->set_error('login_id' => 'DUPLICATION');
}
if ($validator->has_error) {
...
}
# in your tmpl
<ul>
? for my $msg ($validator->get_error_messages) {
<li><?= $msg ?></li>
? }
</ul>
FormValidator::Lite is simple, fast implementation for form validation.
IT'S IN BETA QUALITY. API MAY CHANGE IN FUTURE.
http parameter comes from $_
validator args comes from @_
new($q);
Create a new instance.
$q is query like object, such as Apache::Request, CGI.pm, Plack::Request.
check(@rule_ary)
This method do validation.
is_error($key)
Return true value if parameter named $key got error.
is_valid()
Return true value if $validator don't detects error.
This is same as !$validator->has_error().
has_error()
Return true value if $validator detects error.
This is same as !$validator->is_valid().
Set new error to parameter named $param. The rule name is $rule_name.
load_constraints($name)
load constraint components named "FormValidator::Lite::Constraint::${name}".
load_function_message($lang)
Load function message file.
Currently, FormValidator::Lite::Messages::ja and FormValidator::Lite::Messages::en are available.
$validator->set_param_message(
name => 'Your Name',
);
Make relational map for the parameter name to human readable name.
$v->set_message_data(YAML::Load(<<'...'));
---
message:
zip.jzip: Please input correct zip number.
param:
name: Your Name
function:
not_null: "[_1] is empty"
hiragana: "[_1] is not Hiragana"
...
Setup error message map.
$v->set_message('zip.jzip' => 'Please input correct zip number.');
Set error message for the $param and $func.
get_error_messages()
Get whole error messages for $q in arrayref.
Generate error message for parameter $param and function named $func.
get_error_messages_from_param($param)
Get error messages by $q for parameter $param.
Yes, I know. This module is very similar with FV::S.
But, FormValidator::Simple is too heavy for me. FormValidator::Lite is fast!
Perl: 5.010000
FVS: 0.23
FVL: 0.02
Rate FormValidator::Simple FormValidator::Lite
FormValidator::Simple 353/s -- -75%
FormValidator::Lite 1429/s 304% --
Tokuhiro Matsuno <tokuhirom {at} gmail.com>
craftworks
nekokak
the FormValidator::Simple manpage, the Data::FormValidator manpage, the HTML::FormFu manpage
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| FormValidator::Lite - lightweight form validation library |