The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Form::Tiny::Form - main role of the Form::Tiny system

SYNOPSIS

See Form::Tiny::Manual

DESCRIPTION

This role gets automatically mixed in by importing Form::Tiny into your namespace.

ADDED INTERFACE

This section describes the interface added to your class after mixing in the Form::Tiny role.

ATTRIBUTES

Each of the attributes can be accessed by calling its name as a function on Form::Tiny object.

input

Contains the input data passed to the form.

writer: set_input

fields

Contains the validated and cleaned fields set after the validation is complete. Cannot be specified in the constructor.

field_defs

Contains an array reference of Form::Tiny::FieldDefinition instances fetched from the metaclass with context of current instance. Rebuilds everytime new input data is set.

errors

Contains an array reference of form errors which were detected by the last performed validation. Each error is an instance of Form::Tiny::Error.

predicate: has_errors

METHODS

This section describes standalone methods available in the module - they are not directly connected to any of the attributes.

form_meta

Returns the form metaobject, an instance of Form::Tiny::Meta.

new

This is a Moose-flavored constructor for the class. It accepts a hash or hash reference of parameters, which are the attributes specified above.

valid

Performs the validation and returns a boolean which indicates whether the form is valid or not.

Accepts no arguments. Input must be set before calling this method.

check

validate

These methods are here to ensure that a Form::Tiny instance can be used as a type validator itself by other form classes.

check returns a boolean value that indicates whether the validation of input data was successful.

validate does the same thing, but instead of returning a boolean it returns a list of errors that were detected, or undef if none.

Both methods take input data as the only argument.

errors_hash

Helper method which returns errors much like the errors form attribute, but in a hash reference with form field names as keys. Errors not assigned to any specific field end up in empty string key. The values are array references of error messages (strings).

Each field will only be present in the hash if it has an error assigned to it. If no errors are present, the hash will be empty.

It allows you to get errors in format which is easier to navigate:

        {
                '' => [
                        # global form errors
                ],
                # specific field errors
                'field1' => [
                        'something went wrong'
                ],

        }

add_error

        $form->add_error($error_string);
        $form->add_error($field_name => $error_string);
        $form->add_error($error_object);

Adds an error to the form. If $error_object style is used, it must be an instance of Form::Tiny::Error.