I suspect that you're looking for javascript here.
If you want a little popup box that says something like
"You can't submit this form without fulling in the name
field" etc, then that's javascript.
There's an excellent javascript site with hundreds of
examples to do that kind of thing at http://javascript.internet.com.
If instead you want to do form validation after the user has
submitted then HTML::FormValidator as suggested by rob_au is
a good bet.
Alternately you can do something like the following:
use strict;
use CGI;
my $cgi=CGI->new;
print $cgi->header;
my @un_filled;
foreach ($cgi->param)
{
unless($cgi->param($_))
{
push @un_filled, $_;
}
}
if(@un_filled)
{
print "You've forgotten to fill in the following
fields: @un_filled";
exit;
}
# do stuff...
Calling param() in a list context with no arguments returns
all of the parameter names passed to it.
Good luck.
Update: thanks to TomK32 for reminding me. You
never want to rely on Javascript to have validated
your forms. It's nice as a quick reminder to the user that
a field should be filled in, but nothing more than that.
Ideally your script should handle proper validation as a
matter of course. Checking that all the fields you expected
have been passed back, that the fields contain valid entries
(numbers for years, letters for names etc). Javascript
is really just a convenience thing.
Doing taint checking before using these values is also recommended.
Look at perldoc perlsec. |