in reply to Re: Re: Variable from a variable: the dark side?
in thread Variable from a variable: the dark side?

Perhaps you could use CGI.pm's "sticky forms" feature. If you get CGI.pm to create the entire radio button code, it will by default remember the previous value. You can still pub your radio buttons wherever you please in the HTML page. Here's an example to illustrate:
#!/usr/bin/perl -w use strict; use CGI qw(:standard); use HTML::Template; my $template = new HTML::Template (filehandle => \*DATA); my @radio_btns = radio_group(-name=>'type', -value=>[ 1 .. 12 ]); $template->param(type.($_ + 1) => $radio_btns[$_]) for (0 .. $#radio_b +tns); print $template->output; __DATA__ <TMPL_VAR NAME="type1"> <TMPL_VAR NAME="type2"> <TMPL_VAR NAME="type3"> <TMPL_VAR NAME="type4"> <TMPL_VAR NAME="type5"> <TMPL_VAR NAME="type6"> <TMPL_VAR NAME="type7"> <TMPL_VAR NAME="type8"> <TMPL_VAR NAME="type9"> <TMPL_VAR NAME="type10"> <TMPL_VAR NAME="type11"> <TMPL_VAR NAME="type12">

Replies are listed 'Best First'.
Re: Re: Re: Re: Variable from a variable: the dark side?
by bradcathey (Prior) on Apr 19, 2004 at 14:29 UTC
    Thanks ishnid. Great practical solution that I have adapted:
    #!/usr/bin/perl use warnings; use CGI::Carp qw(fatalsToBrowser); use HTML::Template; use strict; use CGI; my $query = new CGI; my $t = $query->param('type'); my @option; $option[1] = $query->param('option1'); $option[2] = $query->param('option2'); $option[3] = $query->param('option3'); $option[4] = $query->param('option4'); my $template = HTML::Template->new(filename => '../htmltemplatetests.t +mpl', associate => $query,die_on_bad_params => 0); { no strict 'subs'; $template->param( type.$t => "1", option.$_ => $option[$_]) for (1 .. 7); } print "Content-type: text/html\n\n"; print $template->output(); exit();
    Of course, the bare 'type' template param returns a strict error, hence the no strict 'subs'. However, all the warnings notwithstanding, I think I'm relatively safe. Thanks all.

    —Brad
    "A little yeast leavens the whole dough."