in reply to Multiple rows in web forms

For checkboxes, you could use a hash, since each checkbox has a different value:

my %field1 = map { $_ => $_; } @{$r->param('field1')}; my %field2 = map { $_ => $_; } @{$r->param('field2')}; my %field3 = map { $_ => $_; } @{$r->param('field3')};

You can check the hashes directrly ($field1{'red'}) or you can then line them up in an array:

my @array_pos = qw( black blue red ); my @field1 = @field1{@array_pos}; my @field2 = @field2{@array_pos}; my @field3 = @field3{@array_pos};

This also handles browsers which return the params in random order, which I'm pretty sure is legal.

Test code:

my $r = { field1 => [qw( black blue red )], field2 => [qw( black red )], field3 => [qw( blue )], }; ... change $r->param(...) to $r->{...} ... my $row_num = 0; printf(" %-6s %-6s %-6s\n", @array_pos); printf(" %-6s %-6s %-6s\n", ('-'x6)x3); foreach my $row (\@field1, \@field2, \@field3) { printf("%d: ", $row_num++); foreach my $col (0..2) { printf("%-6s ", $row->[$col]); } print("\n"); } black blue red ------ ------ ------ 0: black blue red 1: black red 2: blue

Replies are listed 'Best First'.
Re^2: Multiple rows in web forms
by Mutant (Priest) on Sep 29, 2004 at 14:49 UTC
    Thanks... that worked! :)