in reply to Empty form fields error message
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:
Calling param() in a list context with no arguments returns all of the parameter names passed to it.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...
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Empty form fields error message
by TomK32 (Monk) on Nov 25, 2001 at 07:53 UTC | |
by data64 (Chaplain) on Nov 25, 2001 at 08:54 UTC | |
|
Re: Re: Empty form fields error message
by n4mation (Acolyte) on Nov 26, 2001 at 01:45 UTC |