NAME

Dancer::Plugin::HTML::FormsDj - Dancer wrapper module for HTML::FormsDj

SYNOPSIS

 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'
 }; 

DESCRIPTION

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:

save

If defined, it has to point to a subroutine (or a closure) which will be executed if the form data validated successfully.

template

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 %>
redirect

A url path where to redirect the user after successfull posting the data.

get

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.

post

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.

SEE ALSO

HTML::FormsDj

Data::FormValidator

LICENSE AND COPYRIGHT

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.

BUGS AND LIMITATIONS

See rt.cpan.org for current bugs, if any.

INCOMPATIBILITIES

None known.

DEPENDENCIES

Dancer::Plugin::HTML::FormsDj depends on HTML::FormsDj and Data::FormValidator.

AUTHOR

T. Linden <tlinden |AT| cpan.org>

VERSION

0.01