[Israel.pm] Messing with Forms... Again...

Pinkhas Nisanov nisanov at netvision.net.il
Mon Jan 12 05:52:13 PST 2004


On Mon, 2004-01-12 at 11:17, Yuval Yaari wrote:

> The form validation will be done in mod_perl's handler subroutine.
> 
> Then the validation function will either give an error (put it in the 
> session, or using pnotes) and the autohandler of the forms will display 
> it (so the forms won't contain any code, but the autohandler will) OR 
> will redirect to the next page (either a thank you message or the next 
> part of the form).
> 
> This probably keeps everything clean(er).
> 
> Now, since I am familiar with not-being-correct-about-field-names (the 
> HTML coder uses FirstName and the Perl coder uses first_name etc)
> I would like to create some data-structure to keep this easy.

where this data structure will be stored?

> 
> Also this data strucute should keep some information about:
> 
> * The form's next part (URI or something)
> * The form's validation function (subroutine reference, the params will 
> be passed to it)
> * The form's "action" function (or maybe I should keep it inside the 
> validation function?)
> 
> I also have no idea what's the FORM's ACTION should be (since 
> everything's done using the mod_perl handler subroutine).

> Any idea about how to implement everything would be appreciated.
> Anyone here ever created a big site and wants to share how he 
> implemented forms handling?

Basic idea that all "business" functionality will be placed
in perl modules activated by mod_perl handlers, html files
( or templates ) will be responsible only for presentation.
mod_perl handlers will be activated in earlier phases of apache
request loop, so you can redirect request to different html.
e.g.:
if you want to catch form:
<form action="/some_where/some_thing">

define in httpd.conf:
<Location /some_where/some_thing>
	SetHandler perl-script
	PerlFixupHandler My::Handler::For::Something
</Location>

"My::Handler::For::Something" module:

package My::Handler::For::Something;
use Apache;

sub handler{
	my $r = shift;
	my $getInput = $r->args();
	my $postInput;
	$r->read( $postInput, $r->header_in('Content-length'));

	my $newLocation = requestProcess( $getInput, $postInput);
	$r->uri($newLocation);
	$r->filename( $r->document_root() . $newLocation );
	return OK;
}


If you want pass some data to template system you can do it with
"$r->pnotes()" or create new query string and set it with "$r->args()".

thanks
Pinkhas Nisanov






More information about the Perl mailing list