Re: [Templates] [PL] Coding for Y/N radio buttons
[prev]
[thread]
[next]
[Date index for 2004/10/29]
--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Fri, Oct 29, 2004 at 01:39:32PM -0400, Buddy Burden wrote:
> Rod,
>=20
> >I have several input in a for that are T/F, Y/N, etc. and am getting the=
=20
> >defaults from a database lookup before creating the form. Is there bett=
er=20
> >(ie. more TT2 or perlish) way than doing this way?
>=20
> Well, I don't know that it's particularly more Perl-ish or more TT2, but=
=20
> I always do it this way:
>=20
> <input type=3D"radio" name=3D"GETS_REPORT" value=3D"F"
> [%- 'CHECKED' IF gets_report =3D=3D 'F' %]/>No
> <input type=3D"radio" name=3D"GETS_REPORT" value=3D"T"
> [%- 'CHECKED' IF gets_report =3D=3D 'T' %]/>Yes
>=20
An easier way of doing this is with the CGI module... pass a CGI object (in=
this case 'q') to the template and you can do fun stuff like:
[% q.radio_group(name =3D> 'GETS_REPORT',
values=3D>['T','F'],
default=3D>gets_report,
labels=3D>{'T'=3D>'Yes','F'=3D>'No'}
); %]
If you want to get fancier you make stuff persistent:
[% SET TFlabels =3D {'T'=3D>'Yes','F'=3D>'No'}; %]
[% SET TFvalues =3D ['T','F']; %]
[% q.radio_group(name =3D> 'GETS_REPORT',
values=3D>TFvalues,
default=3D>q.param('GETS_REPORT'),
labels=3D>TFlabels}
); %]
And you can then add more radio groups with the same params dead simply... =
Like say you have an array of questions in a hash with the keys as labels
[% SET TFlabels =3D {'T'=3D>'Yes','F'=3D>'No'}; %]
[% SET TFvalues =3D ['T','F']; %]
[% FOREACH question =3D questions.keys %]
[% q.radio_group(name =3D> question,
values=3D>TFvalues,
default=3D>q.param(questions.$question),
labels=3D>TFlabels}
); %]
[% END %]
VOILA!
BTW... I have noticed that most of the people asking questions and showing =
DBI examples and such seem to hardcode their HTML... am I doing something e=
vil by using the CGI module for all this?
For me at least I love the fact that it handles all the formatting.. keeps =
the html 100% standards compliant and generates things like popup groups an=
d multi selects with ease.
Is there some big performance hit that I am missing? :}
--=20
Todd Freeman Ext 6103 .^. Don't fear the penguins!
Programming Department /V\
Andrews University // \\ http://www.linux.org/
http://www.andrews.edu/~freeman/ /( )\ http://www.debian.org/
^^ ^^
--RnlQjJ0d97Da+TV1
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBgtfvnbl1fXtXLfERAhY6AJ0SXt3egVmirduqICVsUfSpF1LzUQCfQ4uH
LN4WWMs6WbW9kuezgfriY+g=
=AK10
-----END PGP SIGNATURE-----
--RnlQjJ0d97Da+TV1--
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|
 |
 |
Re: [Templates] [PL] Coding for Y/N radio buttons
Todd Freeman 23:53 on 29 Oct 2004
|