---
name: "HTML::Widget::Result"
section: "3pm"
platform: "linux"
package: "libhtml-widget-perl"
version: "1.11-7"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/HTML::Widget::Result"
---

# HTML::Widget::Result(3pm)

Result Class

## 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.
