Author image Peter Mottram
and 1 contributors

NAME

Dancer2::Plugin::TemplateFlute::Form - form object for Template::Flute

ATTRIBUTES

name

The name of the form.

Defaults to 'main',

action

The form action.

writer: set_action
predicate: has_action

errors

Errors stored in a Hash::MultiValue object.

Get form errors:

   $errors = $form->errors;
writer: set_errors

Set form errors (this will overwrite all existing errors):

    $form->set_errors(
        username => 'Minimum 8 characters',
        username => 'Must contain at least one number',
        email    => 'Invalid email address',
    );
clearer: clear_errors

NOTE: Avoid using $form->errors->add() or $form->errors->set() since doing that means that "valid" does not automatically get set to 0. Instead use one of "add_error" or "set_error" methods.

fields

Get form fields:

    $fields = $form->fields;
writer: set_fields
    $form->set_fields([qw/username email password verify/]);
clearer: clear_fields

log_cb

A code reference that can be used to log things. Signature must be like:

  $log_cb->( $level, $message );

Logging is via "log" method.

predicate: has_log_cb

pristine

Determines whether a form is pristine or not.

This can be used to fill the form with default values and suppress display of errors.

A form is pristine until it receives form field input from the request or out of the session.

writer: set_pristine

session

A session object. Must have methods read and write.

Required.

valid

Determine whether form values are valid:

    $form->valid();

Return values are 1 (valid), 0 (invalid) or undef (unknown).

writer: set_valid
clearer: clear_valid

The form status automatically changes to "invalid" when "errors" is set or either "add_errors" or "set_errors" are called.

values

Get form values as hash reference:

    $values = $form->values;
writer: fill

Fill form values:

    $form->fill({username => 'racke', email => 'racke@linuxia.de'});
clearer: clear_values

METHODS

add_error

Add an error:

    $form->add_error( $key, $value [, $value ... ]);

errors_hashed

Returns form errors as array reference filled with hash references for each error.

For example these "errors":

    { username => 'Minimum 8 characters',
      email => 'Invalid email address' }

will be returned as:

    [
        { name => 'username', value => 'Minimum 8 characters'  },
        { name => 'email',    value => 'Invalid email address' },
    ]

from_session

Loads form data from session key form. Returns 1 if session contains data for this form, 0 otherwise.

log $level, @message

Log message via "log_cb".

reset

Reset form information (fields, errors, values, valid) and updates session accordingly.

set_error

Set a specific error:

    $form->set_error( $key, $value [, $value ... ]);

to_session

Saves form name, form fields, form values and form errors into session key form.

AUTHORS

Original Dancer plugin by:

Stefan Hornburg (Racke), <racke at linuxia.de>

Initial port to Dancer2 by:

Evan Brown (evanernest), <evan at bottlenose-wine.com>

Rehacking to Dancer2's plugin2 and general rework:

Peter Mottram (SysPete), <peter at sysnix.com>

BUGS

Please report any bugs or feature requests via GitHub issues: https://github.com/interchange/Dancer2-Plugin-TemplateFlute/issues.

We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2011-2016 Stefan Hornburg (Racke).

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.