I've recently been trying to come up to speed using Data::FormValidator. It's important to note that part of the challenge for me has to do with module familiarity ... while I feel I have a sound working knowledge of Perl in general, when it comes to understanding the nuances of sending and retrieving items to modules, I find myself struggling.

Case in point - I've set up a test form with 8 fields. The first four fields are required, and the last four fields are optional. When submitting the form, I'm intentionally leaving two of the four required fields blank - I'm trying to get FormValidator to spit back some sort of error message(s).

I'm able to have the script report the missing (and required) fields, but I can't seem to get any error message reports back from the module using the $results->(msgs) call. Here's the script code:

#!/usr/bin/perl use CGI qw(:standard); use strict; use Data::FormValidator; my $q = new CGI; my $profile = { required => [qw(one two three four)], optional => [qw(five six seven eight)], msgs =>{}, }; print "Content-type:text/html\n\n"; my %fdat = $q->Vars; my $results = Data::FormValidator->check(\%fdat, $profile); if ($results->has_missing) { foreach ($results->missing() ) { print "missing field name: $_ <br>"; } foreach ($results->msgs() ) { print "msgs output: $_ <br>"; } } exit;
And here's the HTML output:

missing field name: three
missing field name: two
msgs output: HASH(0x81ff9dc)

I've got this feeling that I'm missing something very fundamental here, but for the life of me, I can't figure it out. I've searched high and low for references to results->(msgs), and was unable to understand what little I found .... any help is appreciated.


In reply to Retrieving "msgs" values from Data::FormValidator 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.