perleager has asked for the wisdom of the Perl Monks concerning the following question:

Hey,

I've been playing arond with forms for the last two years and starting to get sick of manually validating every field :). It seems as my skills grow more and more, my demands with forms are needed. I'm currently making a form that has many fields, including a upload field, e-mail, zip code, credit cards, website and telephone fields--All fields that usually need some type of validation.

I'm looking for a Module that can do this job for me. One that I came across to and interested me the most was Data::FormValidator. It seems it can do the jobs I want easily, but I'm wondering if has such as a template system? --So It cant print the error message next to the input field, ex. If input field "First Name" is empty, then when a user tries submitting the form, the error message page will display "Missing Field First Name" next to the input text box.


For those who have used any form validation modules, would you prefer this one to use for my needs? Any other better ones?

I've searched this site along with cpan, and found several, and I would say this one seems best fitting. But before I get started to learn how to use it, I just want to make sure this is the one right for me.

Thanks,
Anthony

Replies are listed 'Best First'.
Re: An Easier Way to Validate Forms
by jdtoronto (Prior) on Mar 16, 2004 at 07:37 UTC
Re: An Easier Way to Validate Forms
by Anonymous Monk on Mar 16, 2004 at 05:10 UTC

    I've been dealing with forms for well over two years and I am still very happy doing manual checks on data, without any module help. You simply create a subroutine that outputs your form and do something like the following:

    # login.pl: #!c:/perl/bin/perl -w $|++; use CGI::Simple; use Template; my $CGI = CGI::Simple->new; my $TMPL = Template->new( { INCLUDE_PATH => '/path/to/templates' } ); my $user = $CGI->param('user') || ''; my $pass = $CGI->param('pass') || ''; form_login('Please enter your member ID and password:') if ( ($user eq '') || ($pass eq '') ); form_login('Invalid member ID/password combination.') unless ( some_auth_method($user, $pass) ); # authentication successfull auth_successfull(do => 'something', now => 'please'); sub form_login { my ($usermsg) = @_; print $CGI->header(); # $TMPL->process('login.tmpl', { $TMPL->process(\*DATA, { $CGI->Vars(' '), title => 'Member Login', usermsg => $usermsg } ); exit; } __DATA__ [% USE HTML %] [% INCLUDE header.tmpl %] <p>[% HTML.escape(usermsg) %]</p> <form action="/path/to/login.pl" method="post"> Member ID: <input type="text" name="user" value="[% HTML.escape(user) %]" size="20" maxlength="15" /><br /><br /> Password: <input type="password" name="pass" value="[% HTML.escape(pass) %]" size="20" maxlength="20" /><br /><br /> <input type="submit" value="login now" /> </form> [% INCLUDE footer.tmpl %]