simple form validation in dancer/perl

Posted by devnull on Stack Overflow See other posts from Stack Overflow or by devnull
Published on 2012-09-10T00:50:44Z Indexed on 2012/09/10 3:38 UTC
Read the original article Hit count: 196

Filed under:
|

I am trying to do a simple form validation in perl dancer but I was wondering what would be the best way to validate simple parameters (e.g. field cannot be empty, validity of the email, minimum length of a field) in dancer/perl without any extra plugin or CPAN module

here is the code so far

post '/register' => sub {

my $db = connect_db();
my $sql = 'insert into users (username, email, password, motivation) values (?, ?, ? ,?)';
my $sth = $db->prepare($sql) or die $db->errstr;
$sth->execute(params->{'username'}, params->{'email'},params->{'password'}, params->{'motivation'}) or die $sth->errstr;

set_flash('Hey you signed up !');
redirect '/thanks';
};

I did google it and I found several ways to do validation using CPAN modules like Form::Foo but how do it without that ?

© Stack Overflow or respective owner

Related posts about perl

Related posts about dancer