dws has asked for the wisdom of the Perl Monks concerning the following question:
I'm using template to build a set of semi-complicated pages. Each page holds a form. When submitted, validation logic checks the consistency of the data that comes in via text fields, radio buttons, and a stray checkbox. If validation fails, I reissue the page with all of the input boxes filled in as they were, and a pithy message at the top explaining what's wrong.
Trying to maintin input state leads to a messy problem; one that I'm hoping someone has come up with a clean approach to.
Regenerating text fields is easy. The templates say
and as long as I've given the template a parameter binding for "foo", things work fine. A major plus is that I can view the template in a browser to verify formatting.<input type=text name=foo value='<TMPL_VAR NAME="foo">'>
Radio buttons are a messier. I want to leave as much clean HTML in the template as possible. But how to regenerate them such that I don't lose the selection? I could do violence to the HTML, and write something like:
where "bar1_checked" will either be "" or "checked". But this screws up the HTML in the template, rendering it unviewable.<input type=radio name=bar value="bar1" <TMPL_VAR NAME="bar1_checked">>
The other approach is to do something like
around each radio box. The template is then viewable as HTML, though each box appears twice, which screws up formatting. To keep tables from getting screwed up, I resorted to writing<TMPL_IF NAME="bar1_checked"> <input type=radio name=bar value="bar1" checked> <TMPL_ELSE> <input type=radio name=bar value="bar1"> </TMPL_IF>
but this bloated my templates something aweful, and requires that I invent a new template parameter per radio box. With a dozen radio boxes, the space ads up.<TMPL_IF NAME="bar1_checked"> <tr> <td><input type=radio name=bar value="bar1" checked></td> <td>$47</td> </tr> <TMPL_ELSE> <tr> <td><input type=radio name=bar value="bar1"></td> <td>$47</td> </tr> </TMPL_IF>
Does anyone know of a clean approach that will let me generate a page with arbitrary radio buttons checked, without having to break or bloat the HTML? Or am I S.O.L.?
P.S. JavaScript is not on option.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Template and checking arbitrary radio buttons
by blokhead (Monsignor) on Jan 03, 2003 at 06:39 UTC | |
|
Re: HTML::Template and checking arbitrary radio buttons
by pfaut (Priest) on Jan 03, 2003 at 13:35 UTC | |
|
(jeffa) Re: HTML::Template and checking arbitrary radio buttons
by jeffa (Bishop) on Jan 03, 2003 at 18:17 UTC | |
|
Re: HTML::Template and checking arbitrary radio buttons
by tjmather (Initiate) on Jan 04, 2003 at 01:12 UTC | |
|
Re: HTML::Template and checking arbitrary radio buttons
by shotgunefx (Parson) on Jan 03, 2003 at 18:23 UTC |