| CGI-Application-Plugin-FormValidator-Simple documentation | Contained in the CGI-Application-Plugin-FormValidator-Simple distribution. |
CGI::Application::Plugin::FormValidator::Simple - Validator for CGI::Application with FormValidator::Simple
use CGI::Application::Plugin::FormValidator::Simple;
$self->validator(
plugins => [ 'Japanese', 'Number::Phone::JP' ],
options => {
charset => 'euc',
},
messages => {
user => {
param1 => {
NOT_BLANK => 'Input name!',
ASCII => 'Input name with ascii code!',
},
mail1 => {
DEFAULT => 'email is wrong.!',
NOT_BLANK => 'input email.!'
},
},
company => {
param1 => {
NOT_BLANK => 'Input name!',
},
},
},
);
$self->form(
param1 => [qw/NOT_BLANK ASCII/, [qw/LENGTH 4 10/]],
param2 => [qw/NOT_BLANK/, [qw/JLENGTH 4 10/]],
mail1 => [qw/NOT_BLANK EMAIL_LOOSE/],
mail2 => [qw/NOT_BLANK EMAIL_LOOSE/],
{ mail => [qw/mail1 mail2/] } => ['DUPLICATION'],
);
print $self->form->valid('param1');
if ( some condition... ) {
$self->form(
other_param => [qw/NOT_INT/],
);
}
if ( $self->form->has_missing || $self->form->has_invalid ) {
if ( $self->form->missing('param1') ) {
...
}
if ( $self->form->invalid( param1 => 'ASCII' ) ) {
...
}
if ( $self->form->invalid( param3 => 'MY_ERROR' ) ) {
...
}
}
This plugin for CGI::Application allows you to validate request parameters with FormValidator::Simple. See FormValidator::Simple for more information.
Gosuke Miyashita, <gosukenator@gmail.com>
Copyright (C) 2005 by Gosuke Miyashita
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
| CGI-Application-Plugin-FormValidator-Simple documentation | Contained in the CGI-Application-Plugin-FormValidator-Simple distribution. |
package CGI::Application::Plugin::FormValidator::Simple; use strict; use vars qw($VERSION @EXPORT); use warnings; use FormValidator::Simple; require Exporter; @EXPORT = qw( validator form ); sub import { goto &Exporter::import } $VERSION = '0.03'; sub validator { my $self = shift; my %params = @_; my $plugins = $params{plugins}; FormValidator::Simple->import(@$plugins) if $plugins; my $options = $params{options}; $self->{validator} = FormValidator::Simple->new(%$options); if (exists $params{messages}){ FormValidator::Simple->set_messages($params{messages}); } return $self->{validator}; } sub form { my $self = shift; if ($_[0]) { my $form = $_[1] ? [@_] : $_[0]; $self->validator() unless $self->{validator}; $self->{form} = $self->{validator}->check($self->query, $form); } return $self->{form}; } 1; __END__