NAME
HTML::Widget::Result - Result Class
SYNOPSIS
see HTML::Widget
DESCRIPTION
Result Class.
METHODS
$self->action($action)
Contains the form action.
$self->as_xml
Returns xml.
$self->container($tag)
Contains the container tag.
$self->enctype($enctype)
Contains the form encoding type.
$self->error( $name, $type )
$self->errors( $name, $type )
Returns a list of HTML::Widget::Error objects.
my @errors = $form->errors;
my @errors = $form->errors('foo');
my @errors = $form->errors( 'foo', 'ASCII' );
$self->element($name)
$self->elements($name)
Returns a HTML::Widget::Container object for element or a list of HTML::Widget::Container objects for form.
my @form = $f->element;
my $age = $f->element('age');
$self->empty_errors(1)
Create spans for errors even when there's no errors.. (For AJAX validation validation)
$self->has_error($name);
$self->has_errors($name);
$self->have_errors($name);
Returns a list of element names.
my @names = $form->has_errors;
my $error = $form->has_errors($name);
$self->id($id)
Contains the widget id.
$self->legend($legend)
Contains the legend.
$self->method($method)
Contains the form method.
$self->param($name)
Returns valid parameters with a CGI.pm-compatible param method. (read-only)
$self->params($params)
$self->parameters($params)
Returns validated params as hashref.
$self->subcontainer($tag)
Contains the subcontainer tag.
$self->strict($strict)
Only consider parameters that pass at least one constraint valid.
$self->valid
Returns a list of element names.
my @names = $form->valid;
my $valid = $form->valid($name);
add_valid <key>,<value>
Adds another valid value to the hash.
add_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.