Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It looks like you are attempting to validate information passed from form input fields in a CGI script. For this, I would suggest that you might want to look at either HTML::FormValidator or Data::FormValidator - These modules allow for validation of not only the presence of form input fields in the passed CGI parameters, but also the adherence of these fields to allowed formats. For example:

use CGI; use Data::FormValidator; my $cgi = CGI->new; my $validator = Data::FormValidator->new({ 'form_input' => { 'required' => [ qw/ first second clan nick pass repass e +mail reemail street postal city country / ], 'constraints' => { 'email' => 'email', 'pass' => '/^[\w\d\-\ ]{1,}$/', 'reemail' => 'email', 'repass' => '/^[\w\d\-\ ]{1,}$/' }, 'filters' => [ qw/ trim / ] } }); my %params = map { $_ => $cgi->param($_) } $cgi->param(); my ( $valid, $missing, $invalid, $unknown ) = $validator->validate( \% +params, 'form_input' );

This little snippet of code performs a number of tasks:

  • Creates a new CGI object, $cgi.

  • Creates a new Data::FormValidator object with a input validation profile called 'form_input' - This input validation profile defines the required fields and sets regular expression constraints on some of them (email, pass, reemail and repass) which need to be met for the field to be considered as 'valid'.

  • Creates a hash of CGI parameters, indexed by the parameter field name, and,

  • Validates the CGI form input fields with the Data::FormValidator validator against the form_input validation profile - This returns four array references containing those fields which are valid, invalid, missing and unknown respectively.


In reply to Re: Hmm I get this error from $q's by rob_au
in thread Hmm I get this error from $q's by andrew

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (6)
    As of 2018-05-25 21:38 GMT
    Find Nodes?
      Voting Booth?