GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::FormValidator::Results(3) User Contributed Perl Documentation Data::FormValidator::Results(3)

Data::FormValidator::Results - results of form input validation.

    my $results = Data::FormValidator->check(\%input_hash, \%dfv_profile);

    # Print the name of missing fields
    if ( $results->has_missing ) {
    for my $f ( $results->missing ) {
        print $f, " is missing\n";
    }
    }

    # Print the name of invalid fields
    if ( $results->has_invalid ) {
    for my $f ( $results->invalid ) {
        print $f, " is invalid: ", $results->invalid( $f ), "\n";
    }
    }

    # Print unknown fields
    if ( $results->has_unknown ) {
    for my $f ( $results->unknown ) {
        print $f, " is unknown\n";
    }
    }

    # Print valid fields
    for my $f ( $results->valid() ) {
        print $f, " =  ", $results->valid( $f ), "\n";
    }

This object is returned by the Data::FormValidator "check" method. It can be queried for information about the validation results.

This method returns true if there were no invalid or missing fields, else it returns false.

As a shorthand, When the $results object is used in boolean context, it is overloaded to use the value of success() instead. That allows creation of a syntax like this one used in "CGI::Application::Plugin::ValidateRM":

 my $results = $self->check_rm('form_display','_form_profile') || return $self->dfv_error_page;

In list context with no arguments, it returns the list of fields which contain valid values:

 @all_valid_field_names = $r->valid;

In a scalar context with no arguments, it returns an hash reference which contains the valid fields as keys and their input as values:

 $all_valid_href = $r->valid;

If called with one argument in scalar context, it returns the value of that "field" if it contains valid data, "undef" otherwise. The value will be an array ref if the field had multiple values:

 $value = $r->valid('field');

If called with one argument in list context, it returns the values of "field" as an array:

 @values = $r->valid('field');

If called with two arguments, it sets "field" to "value" and returns "value". This form is useful to alter the results from within some constraints. See the Data::FormValidator::Constraints documentation.

 $new_value = $r->valid('field',$new_value);

This method returns true if the results contain missing fields.

In list context it returns the list of fields which are missing. In a scalar context, it returns an array reference to the list of missing fields.

If called with an argument, it returns true if that "field" is missing, undef otherwise.

This method returns true if the results contain fields with invalid data.

In list context, it returns the list of fields which contains invalid value.

In a scalar context, it returns an hash reference which contains the invalid fields as keys, and references to arrays of failed constraints as values.

If called with an argument, it returns the reference to an array of failed constraints for "field".

This method returns true if the results contain unknown fields.

In list context, it returns the list of fields which are unknown. In a scalar context, it returns an hash reference which contains the unknown fields and their values.

If called with an argument, it returns the value of that "field" if it is unknown, undef otherwise.

This method returns a hash reference to error messages. The exact format is determined by parameters in the "msgs" area of the validation profile, described in the Data::FormValidator documentation.

NOTE: the "msgs" parameter in the profile can take a code reference as a value, allowing complete control of how messages are generated. If such a code reference was provided there, it will be called here instead of the usual processing, described below. It will receive as arguments the Data::FormValidator::Results object and a hash reference of control parameters.

The hashref passed in should contain the same options that you can define in the validation profile. This allows you to separate the controls for message display from the rest of the profile. While validation profiles may be different for every form, you may wish to format messages the same way across many projects.

Controls passed into the <msgs> method will be applied first, followed by ones applied in the profile. This allows you to keep the controls you pass to "msgs" as "global" and override them in a specific profile if needed.

In a few cases, a constraint may discover meta data that is useful to access later. For example, when using Data::FormValidator::Constraints::Upload, several bits of meta data are discovered about files in the process of validating. These can include "bytes", "width", "height" and "extension". The "meta()" function is used by constraint methods to set this data. It's also used to access this data. Here are some examples.

 # return all field names that have meta data
 my @fields = $results->meta();

 # To retrieve all meta data for a field:
 $meta_href = $results->meta('img');

 # Access a particular piece:
 $width = $results->meta('img')->{width};

Here's how to set some meta data. This is useful to know if you are writing your own complex constraint.

    $self->meta('img', {
        width  => '50',
        height => '60',
    });

This function does not currently support multi-valued fields. If it does in the future, the above syntax will still work.

Data::FormValidator, Data::FormValidator::Filters, Data::FormValidator::Constraints, Data::FormValidator::ConstraintsFactory

Author: Francis J. Lacoste <francis.lacoste@iNsu.COM> Maintainer: Mark Stosberg <mark@summersault.com>

Copyright (c) 1999,2000 iNsu Innovations Inc. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms as perl itself.

2017-08-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.