I've been very successful using Data::FormValidator along with CGI::Application::ValidateRM and HTML::Template. With these it becomes a breeze to write custom validations and untainting routines , return specific, customized, and context specific error messages.

What's more, the HTML template system allows the designer to position and style the error message. Also, the custom error messages can be kept in seperate file for easy editing (I use Config::General for loading and reading the file). My error config file looks like this:

<msgs> any_errors = err__ prefix = err_ <constraints> OK_dn_unique = Domain name already used within Citigroup OK_dn = Badly formed domain name OK_words = Illegal character in string OK_chars = Illegal character or space in string OK_sql = Illegal SQL character in string OK_phone_chars = Illegal phone character(s) or format OK_int = Illegal integer OK_date = Illegal date character(s) or format OK_email = Illegal email format </constraints> </msgs>

The key of the constraints hash in the function name of the constraint. Details are explained clearly in the validateRM docs. Here's an example validate/untaint function I wrote (note how simple it is):

sub match_OK_phone_chars { my $val = shift; if ( $val =~ /^([-\d. \(\)]{10,}[extEX .-\d]*)$/ ) { return $1; } else { return undef; } }
I highly recommend using these modules.

-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday


In reply to Re: Form validation: preferred modules? by freddo411
in thread Form validation: preferred modules? by Hagbone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.