For Programmers: Free Programming Magazines  


Home > Archive > PERL Modules > February 2005 > [RFC] HTML::Formit.pm









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [RFC] HTML::Formit.pm
mjl69

2005-02-16, 8:57 pm

I have written a humble little module that I am planning to put on CPAN.
Please take a look at the following documentation and tell me what you think.
I have found it to be useful in my own work.


NAME
HTML::Formit - A CGI Form Generator

SYNOPSIS
Generate simple forms with HTML widgets for use with your CGI programs.

DESCRIPTION
HTML::Formit is a class that helps to generate useful HTML forms that are
neatly lined up in a table.

Usage:

#!/usr/bin/perl
use warnings;
use strict;
use CGI (':standard');
use HTML::Formit;

my $p = new HTML::Formit;
$p->load([
'name',
'date of birth',
'life story::textarea::4::50',
'favorite ice cream::radio_group::vanilla::chocolate',

'favorite parents::checkbox_group::mom::dad',
'favorite color::scrolling_list::red::blue::pink::
purple::green'
]);
print start_form();
print $p->generate;
print submit(-name=>'add');
print end_form();

#or you can load from a file...
my $q = new HTML::Formit;
$p->load('data.dat', \%defaults);#the name of your data file with form structure data

The optional %defaults ref should contain keys as field names and
default values to insert #this will trigger override for the fields
listed and use these values.

The load method loads data for the form structure which must be in the following format:

field1::textarea::10::30::Hello, how are::you?
field2::textfield::50::Hello, I am::fine!
field3::radio_group::I am::fine::too
field4::checkbox_group::I::am::a robot
field5::popup_menu::do you::want to::be a::chicken?
field6::scrolling_list::5::yes::I::do!

The values on each line are separated by '::'. You cannot use :: in a
string because of this. The first value is the name of the field. The
second is the type of widget you want which must be one of the 5 listed
above. If it is not, textfield will be used by default. If it is a
textarea, the 3rd and 4th values on the line are the row and column
values. The remainder of the line is the default text, if any, that will
go in the textarea. Any ::'s mixed in with this text will convert to
spaces. A textfield has its size as the third value. For the other three
types, each item separated by ::'s will be a different choice given.
Experiment with it to get the hang of it. If you just pass a reference
to an array of words, you will get a list of textfields with these
labels by default.

AUTHOR
Mark Leeds

BUGS
If you leave out the row and col values for textarea or the length value
for textfield and you also want default text, you may lose part of your
default text as it will be assumed to be these values.

SEE ALSO
http://stein.cshl.org/WWW/software/CGI/

COPYRIGHT
2005 Mark Leeds
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com