Form::Sensible::Validator::Result - Validation results for a given form.
my $result = $form->validate();
if (!$result->is_valid()) {
foreach my $key ( keys %{$result->error_fields()} ) {
foreach my $message ( @{ $result->error_fields->{$key} } ) {
print $message;
}
}
}
The
"Form::Sensible::Validator::Result|Form::Sensible::Validator::Result"
class is used to store the results of form validation. It is very simple to
work with and has some additional methods to make it more familiar to anyone
who has used FormValidator::Simple. The additional methods are intended to
function similar to the FormValidator::Simple Results class
- "is_valid()"
- Returns true if the form passed validation, false otherwise.
- "error_fields"
- Returns a hashref containing "fieldname =>
error_array" pairs. Each field with an error will be present
as a key in this hash and the value will be an arrayref containing one or
more error messages.
- "missing_fields"
- Works exactly as error_fields, only contains only entries for fields that
were required but were not present.
- "add_error($fieldname, $message)"
- Adds $message as an error on the field provided.
There can be more than one error message for a given field.
- "add_missing($fieldname, $message)"
- Adds $message as an missing field error on the
field provided. Like errors, there can be more than one missing field
message for a given field.
The following routines are things that make
Form::Sensible::Validator results behave more like
"FormValidator::Simple|FormValidator::Simple"'s
Result class.
- 8
- "has_missing"
- Returns true if there were missing values in the form;
- "has_invalid"
- Returns true if any fields in the form were invalid.
- "has_error"
- Returns true if there are any invalid or missing fields with the form
validation. Essentially the inverse of is_valid
- "success"
- Synonym for is_valid. Returns true if all fields passed validation.
- "missing($fieldname)"
- If $fieldname is provided, returns true if the
field provided was missing, false otherwise. If no fieldname is provided,
returns an array of fieldnames that were missing in the form.
- "invalid($fieldname)"
- If $fieldname is provided, returns true if the
field provided was invalid, false otherwise. If no fieldname is provided,
returns an array of fieldnames that were invalid in the form.
- "error($fieldname)"
- If $fieldname is provided, returns true if the
field provided was either missing or invalid, false otherwise. If no
fieldname is provided, returns an array of fieldnames that were either
missing or invalid in the form.
- "message_for($fieldname)"
- Returns all the error messages (including errors and missing
notifications) for the fieldname provided. Returns an empty array if there
are no errors on the given field.
Jay Kuri - <jayk@cpan.org>
Ionzero LLC. <http://ionzero.com/>
Copyright 2009 by Jay Kuri <jayk@cpan.org>
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Hey! The above document had some coding errors, which are explained
below:
- Around line 232:
- '=item' outside of any '=over'