HTML::Widget::Result - Result Class
see HTML::Widget
Result Class.
Arguments: $action
Return Value: $action
Contains the form action.
Return Value: $xml
Returns xml.
Arguments: $tag
Return Value: $tag
Contains the container tag.
Arguments: $enctype
Return Value: $enctype
Contains the form encoding type.
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".
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.
$name
my @form = $f->elements; my $age = $f->elements('age');
"element" is an alias for "elements".
Return Value: \@elements
Accepts the same arguments as "elements", but returns an arrayref of results instead of a list.
Arguments: $name
Looks for the named element and returns a HTML::Widget::Container object for it if found.
If the named element is a Block or NullContainer element, return a list of HTML::Widget::Container objects for the contents of that element.
Exactly the same as "find_elements" in HTML::Widget
Arguments: $bool
Return Value: $bool
Create spans for errors even when there's no errors.. (For AJAX validation validation)
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".
Arguments: $id
Return Value: $id
Contains the widget id.
Arguments: $legend
Return Value: $legend
Contains the legend.
Arguments: $method
Return Value: $method
Contains the form method.
Return Value (scalar context): $value or \@values
Return Value (list context): @values
Returns valid parameters with a CGI.pm-compatible param method. (read-only)
Return Value: \%params
Returns validated params as hashref.
"parameters" is an alias for "params".
Contains the subcontainer tag.
Only consider parameters that pass at least one constraint valid.
Returns true if $widget->process received a $query object.
$widget->process
$query
"is_submitted" is an alias for "submitted".
Return Value: @names
Returns a list of element names. Returns true/false if a name is given.
my @names = $form->valid; my $valid = $form->valid($name);
Arguments: $key, $value
Return Value: $value
Adds another valid value to the hash.
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.
$result
$result->as_xml
Sebastian Riedel, sri@oook.de
sri@oook.de
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTML::Widget, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Widget
CPAN shell
perl -MCPAN -e shell install HTML::Widget
For more information on module installation, please visit the detailed CPAN module installation guide.