Receiving and Validating Docbase Records

The Docbase::Input module will automatically preview input received from a form’s handler. We’ll see how that works shortly. But validating the fields of a record is the responsibility of each Docbase instance. That’s done by customizing the handler for each instance. The handler is always called submit.pl. For the ProductAnalysis docbase, the customized handler—shown in Example 6.4—is stored as /web/cgi-bin/Docbase/ProductAnalysis/submit.pl.

Example 6-4. The ProductAnalysis Version of submit.pl

#!/usr/bin/perl -w ########################################################### # boilerplate for every docbase ########################################################### use strict; use Docbase::Input; use TinyCGI; my $tc = TinyCGI->new(); my $vars = $tc->readParse(); # collect CGI args print $tc->printHeader; # start emitting page my $app = $vars->{app}; my $di = Docbase::Input->new($app); foreach my $key (keys %$vars) # basic cleanup of input text { $vars->{$key} = $di->cleanseInput($vars->{$key}); } my ($warnings,$errors) = docbase_validate(); # validate input $di->processInput($vars,$warnings,$errors); # process input and warnings/errors ########################################################### # custom validation tailored for each docbase ########################################################### sub docbase_validate { my (@warnings) = (); my (@errors) = (); my $mailpat = $di->getMailPat; # accumulate warnings unless ( $vars->{'contact'} ...

Get Practical Internet Groupware now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.