HTML::Widget::Result - Result Class
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 the HTML::Widget::Error manpage objects.
my @errors = $form->errors; my @errors = $form->errors('foo'); my @errors = $form->errors( 'foo', 'ASCII' );
Arguments: $name (optional)
Return Value: @elements
If $name
argument is supplied, returns a the HTML::Widget::Container manpage
object for the first element matching $name
. Otherwise, returns a list
of the HTML::Widget::Container manpage objects for all elements.
my @form = $f->elements; my $age = $f->elements('age');
element is an alias for elements.
Arguments: $name (optional)
Return Value: \@elements
Accepts the same arguments as elements, but returns an arrayref of results instead of a list.
Arguments: $name
Return Value: @elements
Looks for the named element and returns a the HTML::Widget::Container manpage object for it if found.
Arguments: $name
Return Value: @elements
If the named element is a Block or NullContainer element, return a list of the HTML::Widget::Container manpage objects for the contents of that element.
Return Value: @elements
Exactly the same as find_elements in the HTML::Widget manpage
Arguments: $bool
Return Value: $bool
Create spans for errors even when there's no errors.. (For AJAX validation validation)
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.
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.
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)
Return Value: \%params
Returns validated params as hashref.
parameters is an alias for params.
Arguments: $tag
Return Value: $tag
Contains the subcontainer tag.
Arguments: $bool
Return Value: $bool
Only consider parameters that pass at least one constraint valid.
Return Value: $bool
Returns true if $widget->process
received a $query
object.
is_submitted is an alias for submitted.
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);
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.
Sebastian Riedel, sri@oook.de
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.