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.
—Brad "Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|