in reply to Remembering values from an HTML form
Using the aforementioned HTML::Template is a good solution to repopulating an HTML form after Perl-side validation. I do this all day long. H::T has a built-in function that preserves the values from the form:
... my $query = new CGI; ... my $template = HTML::Template->new( filename => "foobar.tmpl", associate => $query);
However, one problem in any of the methods described above, is resetting radio buttons, check boxes, or select/option dropdowns. Besides using the associate function in H::T, you need to set your returning params to trigger which buttons, boxes, or dropdowns have been selected. Here's my messy solution (I'm open to new ways, monks):
Perl: my $vote = $query->param('vote'); my ($voteyes, $voteno); if ($vote == 1) { $voteyes == 1; } elsif ($vote == 2) { $voteno == 1; } $template = param(voteyes => $voteyes, voteno => $voteno); HTML: Yes: <input type="radio" name="vote" value="1"<tmpl_if voteyes> checke +d</tmpl_if> /> No: <input type="radio" name="vote" value="2"<tmpl_if voteno> checked< +/tmpl_if> />
Just a friendly "heads-up." Good luck.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remembering values from an HTML form
by Nevtlathiel (Friar) on Jan 14, 2005 at 17:20 UTC |