Simon Cozens

NAME

Form::Maker - Framework for web forms

SYNOPSIS

  use Form::Maker;
  # Please see Form::Maker::Introduction

DESCRIPTION

METHODS

make

    my $form = Form::Maker->make();
    my $form = Form::Maker->make("Form::Outline::Login");

Creates a new form. If a package name is given, this is used as an outline for the form, and any fields defined in the outline are added to the new form.

add_fields

    $form->add_fields(qw/username password/);

    $form->add_fields(
            Form::Field::Text->new({ name => "username" }),
            Form::Field::Password->new({ name => "password" }),
    );

Adds fields to a form; the arguments may either be Form::Field-derived objects, or names of fields. If the argument is a plain string, then a Form::Field::Text object is created; this may later be changed to a different kind of field by the default Form::Decorator::PredefinedFields.

remove_fields

    $self->remove_fields(qw/password/);

Removes the named fields from the form.

add_button

    $self->add_button("submit");
    $self->add_button( Form::Button->new("whatever") );

Adds a button to the form. If no buttons are explicitly added by the time the form is rendered, the DefaultButtons decorator will add a submit and reset button.

add_validation

    $self->add_validation(
        username => qr/^[a-z]+$/,
        phone    => "Form::Validation::PhoneNumber",
        email    => {
            perl => qr/$RE{email}/,
            javascript => 
                '/^[\w\-\+\._]+\@[a-zA-Z0-9][-a-zA-Z0-9\.]*\.[a-zA-Z]+$/'
        }
    );

Sets the validation method for a given field; the value for each field can be a regular expression, to be used for all validation contexts, a hash mapping validation contexts to regular expressions, or the name of a class which will provide such a hash.

renderer

    $form->renderer("Form::Renderer::TT");

Gets or sets the form's renderer

render

    print $form->render;
    print $form;

This uses the form's renderer to turn the form into a string; this stringification is also done automatically when the form object is used in a string context.

Form elements

These methods return rendered parts of the form

start

end

Return the surrounding tags of the form, as plain text.

fieldset_start

fieldset_end

Return the surrounding tags of the field section of the form, as plain text.

fieldset

Returns the rendered fieldset portion of the form.

fields

Returns the individual fields as Form::Field elements.

AUTHOR

Programmed by Simon Cozens, from a specification by Tony Bowden (tony-form@kasei.com) and Marty Pauley, and with the generous support of Kasei.

COPYRIGHT AND LICENSE

Copyright (C) 2004 by Simon Cozens and Kasei.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.