On Wed, 17 Apr 2002 [EMAIL PROTECTED] wrote:
> What's the simplest way to make sure that all 10 fields have been 
> selected?

This seems pretty straight-forward: param() returns a list of all form 
elements - even the form elements without values. To check that each field 
contains a value.

#! /usr/bin/perl -w
use CGI qw(:standard);

use vars qw(%form_fields @missing);

# Create a hash of the HTML form element names and their labels
%form_fields = (
        company_name    =>      'Company Name',
        job_id          =>      'Job ID',
        job_title       =>      'Job Title'
);

print header(), start_html();
if (count_params() == scalar keys %form_fields) {
        print "All form-fields had values.";
} else {
        print "These form-fields did not have values:", ol(li([@missing]));
}
print end_html();

sub count_params {
        # How many fields have been defined?
        my $fields = scalar keys %form_fields;

        # Loop through each field name and check the value. If no value was given: 
        #  decrement the counter ($fields), and
        #  push the field's label onto a list.
        foreach (keys %form_fields) {
                next if defined param($_);
                push @missing,$form_fields{$_};
                $fields--;
        }
        return $fields;
}


-- 
Eric P.
Los Gatos, CA


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to