NAME

FieldForm -- Handle HTML forms with Field objects

SYNOPSIS

  use HTML::FieldForm;
  use HTML::Field;
  
  # Object constructor
  my $form = HTML::FieldForm->new(    
    part_number      => [ 'Textfield', {
                           primary_key => 1,
                      } ],
    description      => [ 'Textarea', {
                           cols        => 60,
                           rows        => 6,
                      } ],
    purchasing_code =>  [ 'Select', {
                           options     => \@purchasing_codes,
                           labels      => \%purch_codes_labels,
                      } ],
  );
  
  # The returned object is a hash of HTML::Field objects keyed by name:
  my $part_number = $form->{part_number};
  
  # Set the value of the fields from a hash ref
  my %values = (part_number => '16-0021', description => 'Brushplate');
  $form->set_values(\%values);

  # Set the value of the fields from a CGI object
  my $query = new CGI;
  $form->set_values($query);

  # Get the values of all the fields in a hash
  my %data = $form->get_values;

  # Reset all the field values to their defaults
  $form->reset_values;
  
  # Get a hash with editable or read only html (fieldname => html)
  # Specially useful for HTML::Template
  my %editable = $form->editable_html;
  my %readonly = $form->readonly_html;
  my %creation = $form->creation_html;
  
  # Request XHTML instead of HTML
  $field_form->set_xhtml(1); # Gets xhtml
  $field_form->set_xhtml(0); # Gets html (default)
  
  # Request the addition of an ID selector for each form field 
  # (same as its name)
  $field_form->add_id;
  
  # These two last methods return the HTML::FieldForm object, so that
  # you can say:
  %editable = $field_form->xhtml(1)->add_id->editable_html;
  

DESCRIPTION

The goal of this simple module is to perform common actions over a set of HTML form fields in order to get rid of some of the tedious of scripting CGI.

AUTHOR

Julio Fraire, <jfraire@gmail.com<gt>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Julio Fraire

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.3 or, at your option, any later version of Perl 5 you may have available.