in reply to Empty form fields error message
Here's another way. Add a comment - <--error_message--> - to the form page where you want the error message to display, then use something like this:
#!/usr/bin/perl -w use strict; use CGI; # create CGI object my $q = new CGI; # create list of fields to check my @non_empty_form_fields = qw(name email address tel); # store errors here my @err = (); # check fields exist for (@non_empty_form_fields) { unless ( $q->param($_) ) { push @err, "You must complete the '$_' field"; } } # if error, represent if (@err) { # read in form open (FORM,'/path/to/form.html') || die $!; my $form = join '', (<FORM>); close(FORM); # create error message my $err_message = $q->h3('Error'). $q->p('I could not process the form:'). $q->ul( $q->li([@err]) ). $q->p('Check your input and resubmit.'); # put message in page $form =~ s/<!--error_message-->/$err_message/is; # show page print $q->header, $form; exit(0); } # otherwise input ok, so do whatever...
If you are using relative URLs to call page images, you may also want to add a <BASE HREF...> tag to the page (or get the script to add it).
HTH
cLive ;-)
|
|---|