.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::FormHandler::Manual::Errors 3pm" .TH HTML::FormHandler::Manual::Errors 3pm "2022-03-25" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::FormHandler::Manual::Errors \- FormHandler error methods .SH "VERSION" .IX Header "VERSION" version 0.40068 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Manual Index .PP Errors and error messages for HTML::FormHandler. .SH "DESCRIPTION" .IX Header "DESCRIPTION" Errors are added to field or form objects by the field 'add_error' method or the form 'add_form_error' method. FormHandler will perform the 'add_error' for you for built-in validation or 'apply' actions. When performing your own validation in a validation method, you must do the 'add_error' yourself. .PP Errors, along with 'input' and 'value' attributes, are collected in the FormHandler 'result' objects. A number of error retrieving methods are delegated to the field and form classes. .PP The existence (or not) of errors determines whether or not the form has been 'validated'. .SH "Form methods" .IX Header "Form methods" .IP "errors" 4 .IX Item "errors" Returns an array of localized error strings (both field and form errors): .Sp .Vb 1 \& my @errors = $form\->errors; .Ve .Sp Note: this is a form method, not a result method. For the same thing from a result object, use \f(CW\*(C`$result\->form_and_field_errors\*(C'\fR. .IP "has_errors" 4 .IX Item "has_errors" Both 'form' errors and errors from the tree of subfields .Sp .Vb 3 \& if( $form\->has_errors ) { \& \& } .Ve .IP "form_errors, all_form_errors" 4 .IX Item "form_errors, all_form_errors" Returns an arrayref / array of error strings on the form (not including field errors). .Sp .Vb 3 \& foreach my $err ( $self\->all_form_errors ) { \& $output .= "$err"; \& } .Ve .IP "has_form_errors" 4 .IX Item "has_form_errors" Does the form have form_errors? .IP "add_form_error" 4 .IX Item "add_form_error" Add an error to the form which is not associated with a specific field. .Sp .Vb 6 \& sub validate { \& my $self = shift; \& unless( ) { \& $self\->add_form_error(\*(Aq....\*(Aq); \& } \& } .Ve .IP "push_form_errors" 4 .IX Item "push_form_errors" Add a non-localized error to the form. .SH "Field methods" .IX Header "Field methods" The most common error method is probably 'add_error', which you use in the validation process. .PP .Vb 6 \& sub validate_foo { \& my ( $self, $field ) = @_; \& unless ( ) { \& $field\->add_error(\*(AqError condition\*(Aq); \& } \& } .Ve .IP "errors" 4 .IX Item "errors" Returns an array of error strings. .IP "has_errors" 4 .IX Item "has_errors" Does the field have errors? Note that a compound field that contains subfields with errors will not return true for this method. If you want to know if there are errors in the subfields, do 'has_error_fields'. .IP "num_errors" 4 .IX Item "num_errors" .PD 0 .IP "add_error" 4 .IX Item "add_error" .PD Add an error to the field. Localization is performed. .IP "push_errors" 4 .IX Item "push_errors" Add an error without localization. .IP "error_fields" 4 .IX Item "error_fields" In a compound field (and its subclasses, like 'Repeatable'), the list of fields with errors. .SH "Result methods" .IX Header "Result methods" The input, value, and error attributes are actually stored in the result objects. Although most of the methods are delegated to the form and field classes, there are times, such as when rendering (because you might be rendering a result that's been peeled off of the form object), that you may need to use result methods. .PP These are the main methods that you might need to use. .IP "has_errors" 4 .IX Item "has_errors" .PD 0 .IP "errors" 4 .IX Item "errors" .IP "error_results" 4 .IX Item "error_results" .PD The results with errors; 'error_fields' is a wrapper around this. .SH "Messages" .IX Header "Messages" The base field class and the field subclasses have some 'built\-in' error messages. These can be modified by setting the 'messages' hashref in the form or the individual fields. .PP When a message is retrieved in a field with \f(CW\*(C`$field\->get_message(\*(Aqupload_file_\*(Aq)\*(C'\fR for example, the 'get_message' method will look first in user-set field specific messages, then in user-supplied form messages, finally in messages provided by the field classes. .PP .Vb 3 \& package MyApp::Form; \& use HTML::FormHandler::Moose; \& extends \*(AqHTML::FormHandler\*(Aq; \& \& sub build_messages { \& return { required => \*(Aq....\*(Aq, my_message => \*(Aq....\*(Aq }; \& } \& ... \& my $form = MyApp::Form\->new( messages => { required => \*(Aq...\*(Aq, ...} ); \& ... \& has_field \*(Aqmy_field\*(Aq => ( messages => { required => \*(AqPlease provide a my_field\*(Aq }, \& required => 1 ); .Ve .SH "AUTHOR" .IX Header "AUTHOR" FormHandler Contributors \- see HTML::FormHandler .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Gerda Shank. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.