%doc>
(within a form)
<& /elements/auto-table.html,
table => 'mytable',
template_row = 'mytemplate',
rows => [
{ field1 => 'foo', field2 => 'CA', ... },
{ field1 => 'bar', field2 => 'TX', ... }, ...
],
&>
or if you prefer:
...
fieldorder => [ 'field1', 'field2', ... ],
rows => [
[ 'foo', 'CA' ],
[ 'bar', 'TX' ],
],
In the process/ handler, something like:
my @rows;
my %vars = $cgi->Vars;
for my $k ( keys %vars ) {
$k =~ /^${pre}magic(\d+)$/ or next;
my $rownum = $1;
# find all submitted names ending in this rownum
my %thisrow =
map { $_ => $vars{$_} }
grep /^(.*[\d])$rownum$/, keys %vars;
$thisrow->{num} = delete $thisrow{"${pre}magic$rownum"};
push @rows, $thisrow;
}
%doc>
<%init>
my %opt = @_;
my $pre = '';
$pre = $opt{'table'} . '_' if $opt{'table'};
my $template_row = $opt{'template_row'}
or die "auto-table requires template_row\n"; # a DOM id
# rows that we will preload, as hashrefs of name => value
my @rows = @{ $opt{'data'} || [] };
foreach (@rows) {
# allow an array of FS::Record objects to be passed
if ( blessed($_) and $_->isa('FS::Record') ) {
$_ = $_->hashref;
}
}
my $fieldorder = $opt{'fieldorder'} || [];
%init>