I posted the original message, but my code is not an alternative to CGI -
it's a supplement to validate a form-fed CGI script and that certain
elements were filled out by the user. It requires CGI, actually.
Found a link that described how to do this on the JavaScript side:
http://www.webdeveloper.com/javascript/js_form_example.html
Jason
Code (assumes you already printed the HTML header and takes in two
arguments: the CGI object and a hash table of required fields):
sub checkRequiredFields {
my ($formHandle, %reqdFields) = @_;
my ($incomplete) = 0;
my (@incFields) = ();
foreach $field (keys %reqdFields) {
if ($field =~ /(.*)\|\|(.*)/) {
$incomplete = 1 && push (@incFields, $reqdFields{$field})
if ( (!grep(/$1\b/, $formHandle->param) ||
$formHandle->param($1) eq '') &&
(!grep(/$2\b/, $formHandle->param) ||
$formHandle->param($2) eq '') );
} else {
$incomplete = 1 && push (@incFields, $reqdFields{$field})
if !grep(/$field\b/, $formHandle->param) ||
$formHandle->param($field) eq '';
}
}
if ($incomplete) {
print "<H2>Incomplete Form</H2>\n";
print "You missed the required fields:<BR>\n<UL>\n";
foreach $incField (@incFields) { print "<LI>$incField\n"; }
print "</UL>\n";
print "<CENTER><I>Use your browser's back button & try
again</I></CENTER>\n";
exit; # I couldn't just use the die, b/c it wouldn't format the
$msg like I wanted
}
}
----------------------------------
Example Hash:
%requiredFields = ( 'upload_file' => 'Document
Source',
'doc_url||docfile' => 'Specify
either Document URL or Document File',
'capture_date' => 'Capture
Date',
'contributor_type' =>
'Contributor Type' );
----- Original Message -----
From: "Curtis Poe" <[EMAIL PROTECTED]>
To: "CGI Beginners" <[EMAIL PROTECTED]>
Sent: Monday, July 09, 2001 12:41 PM
Subject: Re: Required Fields Module
> --- fliptop <[EMAIL PROTECTED]> wrote:
> > > > > since I don't use CGI.pm for basic web stuff, I have my own
function
> > > > > getting values out of the query string, and it was only giving me
the last
> > > > > value of MultipleSelectMenu -- bad :(
> > > >
> > > >that's why you'll be better off just always using CGI.pm or some
other
> > > >modern equivalent.
> > >
> > > I don't agree. Why should I spend all that time loading up CGI.pm
when all
> > > I want to get is the query string? It's far more efficient to have a
> > > subroutine that does that. If I want to use CGI.pm's many features,
such
> > > as form writing, or file uploading, or whatever, it's worth loading
the
> > > module up. But for simple, one-time things like getting user input, I
> > > think it's overkill to use CGI.pm.
>
> Gah!!! I wish I had seen this thread sooner (I've been out with the flu).
>
> Whoever wrote their own alternative to CGI.pm, post your code and I'll
point out plenty of flaws
> in it. I'm sure I'll find at least 5 (one of these days I'll find fewer
in a hand-rolled version,
> but I haven't yet).
>
> I'm not saying this to be rude, but CGI tends to be much trickier than
people think even though it
> looks really simple. If you plan to do any long-term work with CGI, why
not go with the industry
> standard? It's the standard because it works.
>
> Oh, and about the overhead of loading CGI.pm: if you have a site that is
so slow that loading
> CGI.pm is causing performance issues, than CGI.pm is the last of your
worries. If you are worried
> that you'll get to the point where CGI.pm will cause those performance
issues, than your
> hand-rolled version will not be adequate. At the very least, check out
CGI::Lite.
>
> Cheers,
> Curtis Poe
>
> =====
> Senior Programmer
> Onsite! Technology (http://www.onsitetech.com/)
> "Ovid" on http://www.perlmonks.org/
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/