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

NAME

Dancer::Plugin::DataFormValidator - Easy access to Data::FormValidator from within Dancer applications

VERSION

version 0.002

SYNOPSIS

  use Dancer;
  use Dancer::Plugin::DataFormValidator;

  post '/foo' => sub {
    if (my $results = dfv ('foo')) {
      # Do some stuff
    } else {
      # Report some failure
    }
  }

DESCRIPTION

Provides an easy way to validate user input based on an input profile (specified as per Data::FormValidator) using a dfv() keyword within your Dancer application.

Configuration

In the simplest case you can use Dancer::Plugin::DataFormValidator without any configuration at all, passing validation profiles each time you call dfv().

To reduce visual clutter when dealing with complex validation profiles, you may optionally specify a profile in the dancer configuration that will be loaded on first use, and which contains multiple validation profiles you can then refer to by name:

 plugins:
   DataFormValidator:
     profile: 'profiles'

dfv()

The dfv() routine can be called several different ways. In all cases it must include either a validation profile name (which must be present in the file loaded via the profile configuration parameter), or a hashref containing the validation profile to be used (see Data::FormValidator for details on what that profile may contain).

If nothing else is included, the parameters Dancer found for the handler will be used. Otherwise, you may hand it a hashref of whatever data you wish it to check.

It will return a Data::FormValidator::Results object you can use however you please.

Explicit validation profile, explicit params

    post '/jazz' => sub {
        if (my $results = dfv ({required => [qw{Name}]}, {Name => 'HorseFeathers'})) {
            do_something ($results->valid)
        } else {
            messages = $results->msgs;
        }
    };

Named validation profile, implicit params

    post '/contact/form' => sub {
        if (my $results = dfv ('contact')) {
            do_something ($results->valid)
        } else {
            messages = $results->msgs;
        }
    };

CONTRIBUTING

This module is developed on Github at:

http://github.com/mdorman/Dancer-Plugin-DataFormValidator

Feel free to fork the repo and submit pull requests.

ACKNOWLEDGEMENTS

Derived, in intent if not actual code, from Dancer::Plugin::FormValidator by Natal Ngétal, <hobbestigrou@erakis.im>

SEE ALSO

Dancer Data::FormValidator

AUTHOR

Michael Alan Dorman <mdorman@ironicdesign.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Ironic Design, Inc..

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.