You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Ken Y. Clark" <kc...@logsoft.com> on 2002/04/26 20:33:58 UTC
Re: How to generate pre-filled forms? (fwd)
Forgot to cc the list.
---------- Forwarded message ----------
Date: Fri, 26 Apr 2002 11:35:37 -0400 (EDT)
From: Ken Y. Clark <kc...@logsoft.com>
To: F.Xavier Noria <fx...@isoco.com>
Subject: Re: How to generate pre-filled forms?
On Fri, 26 Apr 2002, F.Xavier Noria wrote:
> Date: Fri, 26 Apr 2002 16:15:52 +0200
> From: F.Xavier Noria <fx...@isoco.com>
> To: modperl@apache.org
> Subject: How to generate pre-filled forms?
>
> I am writing some modules that receive a form, process it, and return a
> page that includes that very form. Is there a standard way to fill that
> returned form so the user sees the same data he sent there, as CGI.pm
> does?
>
> -- fxn
>
> PS: I am using Apache modules + HTML::Template if that matters.
I'll throw my technique into the ring, too. I use Template Toolkit
most of the time, and I pass the original Apache request object back
to the template as a parameter. Then I call the "param" method to
fill in the "value" of form elements, like so:
In code:
sub handler {
my $r = shift;
my $apr = Apache::Request->new($r);
my $t = Template->new;
my $html;
$t->process('/foo/bar.tmpl', { apr => $apr }, \$html);
$apr->content_type('text/html');
$apr->send_http_header;
$apr->print( $html );
return OK;
}
In template:
<form>
<input name="foo" value="[% apr.param('foo') %]">
<textarea name="text">[% apr.param('description') %]</textarea>
</form>
Nothing gets placed there the first time through as calling
"$apr->param" returns nothing. This seems to work great for me. I've
not used HTML::Template in a while, but possibly you can do this, too?
Template Toolkit makes it easy to call methods (or deference hashes
and hash references) with the "dot" notation.
HTH,
ky
Re: How to generate pre-filled forms? (fwd)
Posted by "F. Xavier Noria" <fx...@isoco.com>.
On 29 Apr 2002 09:16:42 +1000
simran <si...@cse.unsw.edu.au> wrote:
: Have a look at the HTML::FillInForm module as well...
Yeah, thank you, I'll give it a try. I guess this is a natural candidate
for an output chain, the HTML generated by two or three Apache modules
will need that post-process, so I plan to use HTML::FillInForm with
Apache::Filter, it will be the first application of my recent study of
the Cookbook I couldn't have produced before I read it, magnific!
-- fxn
Re: How to generate pre-filled forms? (fwd)
Posted by simran <si...@cse.unsw.edu.au>.
Have a look at the HTML::FillInForm module as well...
it works wonders for me...
On Sat, 2002-04-27 at 04:43, darren chamberlain wrote:
> * Ken Clark <kc...@logsoft.com> [2002-04-26 14:33]:
> > I'll throw my technique into the ring, too. I use Template Toolkit
> > most of the time, and I pass the original Apache request object back
> > to the template as a parameter. Then I call the "param" method to
> > fill in the "value" of form elements, like so:
>
> [-- snip --]
>
> > Nothing gets placed there the first time through as calling
> > "$apr->param" returns nothing. This seems to work great for me. I've
> > not used HTML::Template in a while, but possibly you can do this, too?
>
> The constructor for HTML::Template takes an optional argument names
> "associate", which should point to an object (or reference to a list of
> objects) that can("param"). Paramters in the template that are not
> explicitly filled in using the param method of the HTML::Template object
> are looked for by iterating through this list and calling
> param($template_variable_name), and takes the first non-false value as
> the correct one.
>
> To reuse Ken's illustration:
>
> > In code:
> >
> > sub handler {
> > my $r = shift;
> > my $apr = Apache::Request->new($r);
> > my $t = Template->new;
> > my $html;
> > $t->process('/foo/bar.tmpl', { apr => $apr }, \$html);
> > $apr->content_type('text/html');
> > $apr->send_http_header;
> > $apr->print( $html );
> > return OK;
> > }
>
> sub handler {
> my $r = shift;
> my $apr = Apache::Request->new($r);
> my $t = HTML::Template->new(associate => $apr,
> filename => '/foo/bar.html');
> $apr->content_type('text/html');
> $apr->send_http_header;
> $apr->print( $t->output );
> return OK;
> }
>
> > In template:
> >
> > <form>
> > <input name="foo" value="[% apr.param('foo') %]">
> > <textarea name="text">[% apr.param('description') %]</textarea>
> > </form>
>
> <form>
> <input name="foo" value="<TMPL_VAR NAME="foo">">
> <textarea name="text"><TMPL_VAR NAME="description"></textarea>
> </form>
>
> For the template itself, "foo" will be looked for as $apr->param("foo"),
> and description as $apr->param("description").
>
> (darren)
>
> PS Hi Ken!
>
> --
> The more we disagree, the better the chance that one of us is right.
>
>
Re: How to generate pre-filled forms? (fwd)
Posted by darren chamberlain <dl...@users.sourceforge.net>.
* Ken Clark <kc...@logsoft.com> [2002-04-26 14:33]:
> I'll throw my technique into the ring, too. I use Template Toolkit
> most of the time, and I pass the original Apache request object back
> to the template as a parameter. Then I call the "param" method to
> fill in the "value" of form elements, like so:
[-- snip --]
> Nothing gets placed there the first time through as calling
> "$apr->param" returns nothing. This seems to work great for me. I've
> not used HTML::Template in a while, but possibly you can do this, too?
The constructor for HTML::Template takes an optional argument names
"associate", which should point to an object (or reference to a list of
objects) that can("param"). Paramters in the template that are not
explicitly filled in using the param method of the HTML::Template object
are looked for by iterating through this list and calling
param($template_variable_name), and takes the first non-false value as
the correct one.
To reuse Ken's illustration:
> In code:
>
> sub handler {
> my $r = shift;
> my $apr = Apache::Request->new($r);
> my $t = Template->new;
> my $html;
> $t->process('/foo/bar.tmpl', { apr => $apr }, \$html);
> $apr->content_type('text/html');
> $apr->send_http_header;
> $apr->print( $html );
> return OK;
> }
sub handler {
my $r = shift;
my $apr = Apache::Request->new($r);
my $t = HTML::Template->new(associate => $apr,
filename => '/foo/bar.html');
$apr->content_type('text/html');
$apr->send_http_header;
$apr->print( $t->output );
return OK;
}
> In template:
>
> <form>
> <input name="foo" value="[% apr.param('foo') %]">
> <textarea name="text">[% apr.param('description') %]</textarea>
> </form>
<form>
<input name="foo" value="<TMPL_VAR NAME="foo">">
<textarea name="text"><TMPL_VAR NAME="description"></textarea>
</form>
For the template itself, "foo" will be looked for as $apr->param("foo"),
and description as $apr->param("description").
(darren)
PS Hi Ken!
--
The more we disagree, the better the chance that one of us is right.