If you create 5 copies of a form element with the same name
CGI.pm will return the contents of all occurances of the
that fieldname as an array of the values in the order they were specified.
Update
MidLifeXis has a valid point concerning the order in which the values will be returned. So if the numbers are necessary to specify some type of ordering or precedence go with this revelation
This will simplify your code immensely when you need to drop back to 3 floor plans or increase to 7 floor plans.
In your template:In your form processing cgi:[% FOREACH s = [ 1 .. 5 ] %] <tr> <td> Floor Plan Name </td> <td colspan='3'> [% mycgi.textfield( '-name' => floorplan_name, '-size' => '50', '-default' => THIS_PAGE.$IDX.floorplan_na +me ) %] </td> </tr> [% END %]
--my $q = CGI->new; my @floorplans = $CGI->param('floorplan_name'); # How many plans arrived? my $num_plans = @floorplans; # Looping over my plans foreach my $plan ( @floorplans ) { &do_the_plan( $plan ) }
In reply to You don't even need to do that (was Re: Template::Toolkit: better way to generate variable names?)
by clscott
in thread Template::Toolkit: better way to generate variable names?
by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |