Dancer::Plugin::Form - Dancer form handler for Template::Flute template engine
Version 0.0061
Display template with checkout form:
get '/checkout' => sub { my $form; $form = form('checkout'); template 'checkout', {form => $form}; };
Retrieve form input from checkout form:
post '/checkout' => sub { my ($form, $values); $form = form('checkout'); $values = $form->values(); };
Reset form after completion to prevent old data from showing up on new form:
$form = form('checkout'); $form->reset;
Dancer::Plugin::Form is used for forms with the Dancer::Template::TemplateFlute templating engine.
Dancer::Plugin::Form
Form fields, values and errors are stored into and loaded from the session key form.
form
Creates Dancer::Plugin::Form object.
Get form name:
$form->name
Set form action:
$form->action('/checkout');
Get form action:
$action = $form->action;
Fill form values:
$form->fill({username => 'racke', email => 'racke@linuxia.de'});
Get form values as hash reference:
$values = $form->values;
Set form values from a hash reference:
$values => $form->values(ref => \%input);
Determine whether form values are valid:
$form->valid();
Return values are 1 (valid), 0 (invalid) or undef (unknown).
Set form status to "valid":
$form->valid(1);
Set form status to "invalid":
$form->valid(0);
The form status automatically changes to "invalid" when errors method is called with error messages.
Set form errors:
$form->errors({username => 'Minimum 8 characters', email => 'Invalid email address'});
Get form errors as hash reference:
$errors = $form->errors;
Returns form errors as array reference filled with a hash reference for each error.
Indicates form failure by passing form errors.
$form->failure(errors => {username => 'Minimum 8 characters', email => 'Invalid email address'});
You can also set a route for redirection:
return $form->failure(errors => {username => 'Minimum 8 characters'}, route => '/account');
Passing parameters for the redirection URL is also possible:
return $form->failure(errors => {username => 'Minimum 8 characters'}, route => '/account', params => {layout => 'mobile'});
Please ensure that you validate input submitted by an user before adding them to the params hash.
params
Set form fields:
$form->fields([qw/username email password verify/]);
Get form fields:
$fields = $form->fields;
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.
Reset form information (fields, errors, values, valid) and updates session accordingly.
Loads form data from session key 'form'. Returns 1 if session contains data for this form, 0 otherwise.
Saves form name, form fields, form values and form errors into session key 'form'.
Stefan Hornburg (Racke), <racke at linuxia.de>
<racke at linuxia.de>
Please report any bugs or feature requests to bug-dancer-template-templateflute at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Template-TemplateFlute. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dancer-template-templateflute at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Form
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Template-TemplateFlute
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Template-TemplateFlute
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Template-TemplateFlute
Search CPAN
http://search.cpan.org/dist/Dancer-Template-TemplateFlute/
Copyright 2011-2015 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.
To install Dancer::Template::TemplateFlute, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Template::TemplateFlute
CPAN shell
perl -MCPAN -e shell install Dancer::Template::TemplateFlute
For more information on module installation, please visit the detailed CPAN module installation guide.