Provided by: libhtml-widget-perl_1.11-4_all
NAME
HTML::Widget::Result - Result Class
SYNOPSIS
see HTML::Widget
DESCRIPTION
Result Class.
METHODS
action Arguments: $action Return Value: $action Contains the form action. as_xml Return Value: $xml Returns xml. container Arguments: $tag Return Value: $tag Contains the container tag. enctype Arguments: $enctype Return Value: $enctype Contains the form encoding type. errors error Arguments: $name, $type Return Value: @errors Returns a list of HTML::Widget::Error objects. my @errors = $form->errors; my @errors = $form->errors('foo'); my @errors = $form->errors( 'foo', 'ASCII' ); "error" is an alias for "errors". elements element Arguments: $name (optional) Return Value: @elements If $name argument is supplied, returns a HTML::Widget::Container object for the first element matching $name. Otherwise, returns a list of HTML::Widget::Container objects for all elements. my @form = $f->elements; my $age = $f->elements('age'); "element" is an alias for "elements". elements_ref Arguments: $name (optional) Return Value: \@elements Accepts the same arguments as "elements", but returns an arrayref of results instead of a list. find_result_element Arguments: $name Return Value: @elements Looks for the named element and returns a HTML::Widget::Container object for it if found. elements_for Arguments: $name Return Value: @elements If the named element is a Block or NullContainer element, return a list of HTML::Widget::Container objects for the contents of that element. find_elements Return Value: @elements Exactly the same as "find_elements" in HTML::Widget empty_errors Arguments: $bool Return Value: $bool Create spans for errors even when there's no errors.. (For AJAX validation validation) has_errors has_error have_errors Arguments: $name Return Value: $bool Returns a list of element names. my @names = $form->has_errors; my $error = $form->has_errors($name); "has_error" and "have_errors" are aliases for "has_errors". id Arguments: $id Return Value: $id Contains the widget id. legend Arguments: $legend Return Value: $legend Contains the legend. method Arguments: $method Return Value: $method Contains the form method. param Arguments: $name Return Value (scalar context): $value or \@values Return Value (list context): @values Returns valid parameters with a CGI.pm-compatible param method. (read-only) params parameters Return Value: \%params Returns validated params as hashref. "parameters" is an alias for "params". subcontainer Arguments: $tag Return Value: $tag Contains the subcontainer tag. strict Arguments: $bool Return Value: $bool Only consider parameters that pass at least one constraint valid. submitted is_submitted Return Value: $bool Returns true if "$widget->process" received a $query object. "is_submitted" is an alias for "submitted". valid Return Value: @names Arguments: $name Return Value: $bool Returns a list of element names. Returns true/false if a name is given. my @names = $form->valid; my $valid = $form->valid($name); add_valid Arguments: $key, $value Return Value: $value Adds another valid value to the hash. add_error Arguments: \%attributes Return Value: $error $result->add_error({ name => 'foo' }); This allows you to add custom error messages after the widget has processed the input params. Accepts 'name', 'type' and 'message' arguments. The 'name' argument is required. The default value for 'type' is 'Custom'. The default value for 'message' is 'Invalid Input'. An example of use. if ( ! $result->has_errors ) { my $user = $result->valid('username'); my $pass = $result->valid('password'); if ( ! $app->login( $user, $pass ) ) { $result->add_error({ name => 'password', message => 'Incorrect Password', }); } } In this example, the $result initially contains no errors. If the login() is unsuccessful though, add_error() is used to add an error to the password Element. If the user is shown the form again using "$result->as_xml", they will be shown an appropriate error message alongside the password field.
AUTHOR
Sebastian Riedel, "sri@oook.de"
LICENSE
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.