Filewatcher File Search File Search
Content Search
» » » » » » Spark-Form-0.1.tar.gz » Content »
pkg://Spark-Form-0.1.tar.gz:10587/Spark-Form-0.1/  info  downloads


    Spark Form - A simple yet powerful forms validation system that promotes

     use Spark::Form;
     use CGI; #Because it makes for a quick and oversimplistic example
     use Third::Party::Field;
     $form = Spark::Form->new(plugin_ns => 'MyApp::Field');
     # Add a couple of inbuilt modules
     $form->add('email','email',confirm_field => 'email-confirm')
          ->add('password','password',regex => qr/^\S{6,}$/),
          #This one will be autoloaded from MyApp::Field::Username
          # And this shows how you can use a third party field of any class name
          ->add(Third::Party::Field->new(name => 'blah'));
     #Pass in a hashref of params to populate the virtual form with data
     #And do the actual validation
     if ($form->validate) {
         print "You are now registered";
     } else {
         print join "\n", $form->errors;

    and over in MyApp/Field/

     package MyApp::Form::Field::Username;
     use base Spark::Form::Field;
     sub validate {
       my ($self,$v) = @_;

       if (length $v < 6 or length $v > 12) {
         $self->error("Usernames must be 6-12 characters long");
       } elsif ($v =~ /[^a-zA-Z0-9_-]/) {
         $self->error("Usernames may contain only a-z,A-Z,0-9, _ and -");
       } else {

    Moose. I've dropped using Any::Moose. If you need the performance
    increase, perhaps it's time to start thinking about shifting off CGI.

  import (%options)
    Allows you to set some options for the forms class.

    class => String
        Optional, gives the basename for searching for form plugins.

        Given 'MyApp', it will try to load form plugins from

    source => String
        Optional, names a plugin to try and extract form data from.

        If unspecified, you will need to call $form->data(\%data);

  add ($thing,@rest)
    If $thing is a string, attempts to instantiate a plugin of that type and
    add it to the form. Requires the second argument to be a string name for
    the field to identify it in the form. Rest will become %kwargs If it is
    an arrayref, it loops over the contents (Useful for custom fields, will
    probably result in bugs for string field names).@rest will be passed in
    each iteration. If it looks sufficiently like a field (implements
    Spark::Form::Field), then it will add it to the list of fields. @rest
    will just become %kwargs

    Uses 'field name' to locate it from the data passed in.

    This is a streaming interface, it returns the form itself.

    Validates the form. Sets "valid" and then also returns the value.

    Allows you to pass in a hashref of data to populate the fields with
    before validation. Useful if you don't use a plugin to automatically
    populate the data.

    This is a streaming interface, it returns the form itself.

    Moose constructor. Test::Pod::Coverage made me do it. Adds "class" to
    the search path for field modules.

  get (Str)
    Returns the form field of that name



    James Laver. <>.

    Thanks to the Django Project, whose forms module gave some inspiration.

    The FAQ: Spark::Form::FAQ

    Copyright (C) 2009 James Laver

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

Results 1 - 1 of 1
Help - FTP Sites List - Software Dir.
Search over 15 billion files
© 1997-2017