1HTML::FormHandler::ManuUasle:r:ECrornotrrsi(b3u)ted PerlHTDMoLc:u:mFeonrtmaHtainodnler::Manual::Errors(3)
2
3
4

NAME

6       HTML::FormHandler::Manual::Errors - FormHandler error methods
7

VERSION

9       version 0.40068
10

SYNOPSIS

12       Manual Index
13
14       Errors and error messages for HTML::FormHandler.
15

DESCRIPTION

17       Errors are added to field or form objects by the field 'add_error'
18       method or the form 'add_form_error' method. FormHandler will perform
19       the 'add_error' for you for built-in validation or 'apply' actions.
20       When performing your own validation in a validation method, you must do
21       the 'add_error' yourself.
22
23       Errors, along with 'input' and 'value' attributes, are collected in the
24       FormHandler 'result' objects. A number of error retrieving methods are
25       delegated to the field and form classes.
26
27       The existence (or not) of errors determines whether or not the form has
28       been 'validated'.
29

Form methods

31       errors
32           Returns an array of localized error strings (both field and form
33           errors):
34
35               my @errors = $form->errors;
36
37           Note: this is a form method, not a result method. For the same
38           thing from a result object, use "$result->form_and_field_errors".
39
40       has_errors
41           Both 'form' errors and errors from the tree of subfields
42
43               if( $form->has_errors ) {
44                   <do something>
45               }
46
47       form_errors, all_form_errors
48           Returns an arrayref / array of error strings on the form (not
49           including field errors).
50
51               foreach my $err ( $self->all_form_errors ) {
52                   $output .= "<span class="error">$err</span>";
53               }
54
55       has_form_errors
56           Does the form have form_errors?
57
58       add_form_error
59           Add an error to the form which is not associated with a specific
60           field.
61
62               sub validate {
63                   my $self = shift;
64                   unless( <some condition> ) {
65                       $self->add_form_error('....');
66                   }
67               }
68
69       push_form_errors
70           Add a non-localized error to the form.
71

Field methods

73       The most common error method is probably 'add_error', which you use in
74       the validation process.
75
76           sub validate_foo {
77               my ( $self, $field ) = @_;
78               unless ( <some_condition> ) {
79                   $field->add_error('Error condition');
80               }
81           }
82
83       errors
84           Returns an array of error strings.
85
86       has_errors
87           Does the field have errors? Note that a compound field that
88           contains subfields with errors will not return true for this
89           method. If you want to know if there are errors in the subfields,
90           do 'has_error_fields'.
91
92       num_errors
93       add_error
94           Add an error to the field. Localization is performed.
95
96       push_errors
97           Add an error without localization.
98
99       error_fields
100           In a compound field (and its subclasses, like 'Repeatable'), the
101           list of fields with errors.
102

Result methods

104       The input, value, and error attributes are actually stored in the
105       result objects. Although most of the methods are delegated to the form
106       and field classes, there are times, such as when rendering (because you
107       might be rendering a result that's been peeled off of the form object),
108       that you may need to use result methods.
109
110       These are the main methods that you might need to use.
111
112       has_errors
113       errors
114       error_results
115           The results with errors; 'error_fields' is a wrapper around this.
116

Messages

118       The base field class and the field subclasses have some 'built-in'
119       error messages.  These can be modified by setting the 'messages'
120       hashref in the form or the individual fields.
121
122       When a message is retrieved in a field with
123       "$field->get_message('upload_file_')" for example, the 'get_message'
124       method will look first in user-set field specific messages, then in
125       user-supplied form messages, finally in messages provided by the field
126       classes.
127
128          package MyApp::Form;
129          use HTML::FormHandler::Moose;
130          extends 'HTML::FormHandler';
131
132          sub build_messages {
133              return { required => '....', my_message => '....' };
134          }
135          ...
136          my $form = MyApp::Form->new( messages => { required => '...', ...} );
137          ...
138          has_field 'my_field' => ( messages => { required => 'Please provide a my_field' },
139              required => 1 );
140

AUTHOR

142       FormHandler Contributors - see HTML::FormHandler
143
145       This software is copyright (c) 2017 by Gerda Shank.
146
147       This is free software; you can redistribute it and/or modify it under
148       the same terms as the Perl 5 programming language system itself.
149
150
151
152perl v5.34.0                      2021-07-2H2TML::FormHandler::Manual::Errors(3)
Impressum