Use a central resource hash to store html form element attributes/description information by name. Then use CGI.pm to generate these elements dynamically.
This gets more interesting with passing in default values and options, like 'nolabels', for dropboxes, checkbox groups, multiselect, radiobuttons, i.e. when you have to pass pointers to arrays or hashes, or flags. See the 'sendemail' field example in the code.
Also, using CGI.pm helps you automate the process of validating the data passed in because the CGI object rebuilds its state with the html form variables passed in. Ask if you don't know what I mean by this.
Note: you might want to make two hashes so extra, unused attributes don't appear in your html form tags. But I didn't worry about it for now.
Send questions to pcleddy@yahoo.com. Sorry if this is not crystal clear.
# $invitestable is a pointer to a array of hashes.
# This 'table' contains prepopulated rows of information.
# Keys in these hashes are the same as the elements in
# @fieldorder below. Uh, oh yea, there is a key called
# 'id' as well, very important.
$q = new CGI;
<fill up $invitestable somehow with code here>
$fielddefs = &defineformfields;
@fieldorder = ('sendemail','firstname', 'lastname', 'companyname', 'em
+ail', 'projectname', 'clientid');
my (@rows);
foreach my $row (@$invitestable) {
foreach my $element (@fieldorder) {
my $function = $fielddefs->{$element}->{function};
$fielddefs->{$element}->{name} = $element . '.' . $row->{id};
$row->{html}->{$element} = $q->$function($fielddefs->{$element
+});
}
}
sub defineformfields {
my %fielddefs = (
sendemail=>{ order=>1, function=>'checkbox_group', values=>['o
+n'], nolabels=>1, defaults=>['on'], title=>'Send' },
email=>{ order=>3, function=>'textfield', size=>11, title=>'Em
+ail' },
date=>{ order=>2, function=>'textfield', size=>12, title=>'Dat
+e' },
fullname=>{ order=>2, function=>'textfield', size=>8, title=>'
+Name' },
firstname=>{ order=>2, function=>'textfield', size=>8, title=>
+'First Name' },
lastname=>{ order=>2, function=>'textfield', size=>9, title=>'
+Last Name' },
companyname=>{ order=>4, function=>'textfield', size=>12, titl
+e=>'Company Name' },
projectname=>{ order=>4, function=>'textfield', size=>10, titl
+e=>'Project Name' },
clientid=>{ function=>'hidden' }
);
return (\%fielddefs);
}