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.


—Brad
"Don't ever take a fence down until you know the reason it was put up." G. K. Chesterton

Replies are listed 'Best First'.
Re: Remembering values from an HTML form
by Nevtlathiel (Friar) on Jan 14, 2005 at 17:20 UTC
    Thank you everyone for your very useful comments and suggestions. Due to some of the modules that you suggested using not being installed (and me not knowing what to do about getting them installed - I've only worked here a week and a half and never used Perl before, but I digress) I decided that the easiest thing to do would probably be to code the form into the Perl and use self_url. It's working perfectly (well, that bit of the script :P ) and it certainly helped me get my head round some of the things I had been trying to avoid in Perl (read: OOP).

    Thanks again :)