Dancer::Plugin::HTML::FormsDj - Dancer wrapper module for HTML::FormsDj
use Dancer::Plugin::HTML::FormsDj; formsdj '/addbook' => { field => { title => { type => 'text', validate => { # some constraint }, required => 1, }, author => { type => 'text', validate => sub { # some constraint }, required => 1, }, }, name => 'registerform', csrf => 1, save => sub { return; }, template => 'addbook', redirect => '/booklist' };
This module is a plugin for Dancer which acts as a handy wrapper around HTML::FormsDj. It adds a new "route" keyword formsdj, which requires two parameters: a url path (a route) and a hashref.
The plugin handles GET and POST requests itself (by generating the routes for it as well) and maintains the CSRF cookie, if this feature is turned on.
The hashref parameter mostly consists of HTML::FormsDj parameters, for details about these refer to its documentation. Beside them there are some parameters unique to Dancer::Plugin::HTML::FormsDj:
If defined, it has to point to a subroutine (or a closure) which will be executed if the form data validated successfully.
The template to be used. Refer to HTML::FormsDj for details about template functions. Important to note: Inside the template refer to the form using the variable name form, eg:
<% form.as_p %>
A url path where to redirect the user after successfull posting the data.
If defined, it has to point to a subroutine (or a closure) which will be executed on a GET request. To access the form use the perl variable $form inside the sub.
If defined, it has to point to a subroutine (or a closure) which will be executed on a POST request. To access the form use the perl variable $form inside the sub.
save will be ignored if post is defined.
HTML::FormsDj
Data::FormValidator
Copyright (c) 2012 T. Linden
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See rt.cpan.org for current bugs, if any.
None known.
Dancer::Plugin::HTML::FormsDj depends on HTML::FormsDj and Data::FormValidator.
T. Linden <tlinden |AT| cpan.org>
0.01
To install Dancer::Plugin::HTML::FormsDj, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::HTML::FormsDj
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::HTML::FormsDj
For more information on module installation, please visit the detailed CPAN module installation guide.