Forgot to cc the list.

---------- Forwarded message ----------
Date: Fri, 26 Apr 2002 11:35:37 -0400 (EDT)
From: Ken Y. Clark <[EMAIL PROTECTED]>
To: F.Xavier Noria <[EMAIL PROTECTED]>
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 <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> 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


Reply via email to