Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a calendar where user's can check boxes per date. The checkbox looks like so:
<input type=checkbox name='date' value='$thisyear-$thismonth-$thisday' +>
This information is submitted and I end with a CGI $q->param object looking like so:
$VAR1 = bless( { '.parameters' => [ 'date', 'bsubmit', 'state' ], 'use +_tempfile' => 1, '.charset' => 'ISO-8859-1', '.fieldnames' => {}, 'pa +ram' => { 'bsubmit' => [ 'Next' ], 'date' => [ '2013-05-9', '2013-05- +10', '2013-05-11' ], 'state' => [ 'add' ] }, 'escape' => 1 }, 'CGI' ) +;
I want to loop through the date parameter in HTML::Template, but not sure how to do it... Here's what I have.
if ( $q->param('bsubmit') eq 'Next' ) { my $template = HTML::Template->new( filename => 'reqinfo.html', as +sociate => $q ); print $template->output; }
And here's reqinfo.html:
<TMPL_IF DATE> <TMPL_LOOP DATE> <b><TMPL_VAR NAME=DATE></b> </TMPL_LOOP> <TMPL_ELSE> <b>You Did Not Select Any Days!</b> </TMPL_IF>
The problem here is that I don't know what the TMPL_VAR should be.

Replies are listed 'Best First'.
Re: HTML::Template and looping through CGI param with multiple values
by walkingthecow (Friar) on Apr 12, 2013 at 03:20 UTC
    This is my question. I thought I was logged in, turns out I was not. Anyway, I can do this like so:
    my @dates=$q->param("date"); my @loop_date=(); while (@dates) { my %row_data; $row_data{DATE} = shift @dates; push(@loop_data, \%row_data); } $template->param(THIS_LOOP => \@loop_data); }
    And then in my reqinfo.html file:
    <TMPL_IF THIS_LOOP> <TMPL_LOOP THIS_LOOP> <b><TMPL_VAR NAME=DATE></b> </TMPL_LOOP> <TMPL_ELSE> <b>You Did Not Select Any Days!</b> </TMPL_IF>
    I can do it that way, but I'd like to know if I can just associate $q (my CGI object) and loop through the values of the date param somehow. That is something I am still curious about.