Hi all,
Please excuse me if this has been discussed before, and decided to not
to be practical.
In writing an application using CGI.pm and HTML::Tempalte, I seem to be
doing an hell of a lot of typing that seems to be very repetitive.
CGI.pm manages form quite well so that the default values of form
elements are only default the first time the form is called, subsequent
calls to the form remember the values. This saves a lot of potentially
error prone typing.
>From what I can tell, HTML::Template can't do this as the default values
are specified in the template file, or (the way I'm doing it) in a
tmpl_var. Unless the form elements are generated via CGI.pm (such as
select statements), there is no way for it to manage the default values
of the form.
How about an additional couple of methods.
1)
cgiparam($q, $param_name, $param_default)
where $q is a CGI object.
This would set the tmpl_var $param_name to the value that
$q->param($param_name) would return, or, if the $q->param($param_name)
didn't exist, it would set it to the value of $param_default.
2)
cgioutput($q)
where $q is a CGI object.
This, would initially check through all tmpl_var variables that had not
been set, and for any it finds, try to see if there is a value for the
equivalent cgi parameter. If there was, it would set the tmpl_var
parameter to that value.
Then it would call output as normal.
I've made a stab at implementing the cgiparam method as a regular
function, cos I know 0 about writing methods, and it seems to do what I
want. Apologies for the look of the code, I don't think my perl style is
particularly good.
sub cgiparam($$$$) {
#this sub will set a tmplvar to either the value of the equivalent cgi
parameter,
#or the value supplied.
my $tmpl = shift;
my $q = shift;
my $param = shift;
my $default = shift;
$tmpl->param($param, defined($q->param($param)) ? $q->param($param) :
$default );
return;
}
If I'm barking up the wrong tree, and there's a much easier way of doing
what I suggest, please let me know.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]