cgi form handler question

Ian Bicking ianb at colorstudy.com
Mon Apr 7 01:02:54 EDT 2003


On Sun, 2003-04-06 at 23:32, DJ_3000 wrote:
> eg I have the fields:
> 
> name
> email
> address
> age
> salary
> 
> 
> the user forgets to input his email and age
> how would i write a for loop to output:
> 
> email
> age
> 
> for name in form.keys():
>         print name

You'd have to define the fields you required, like:

requiredFields = ['name', 'email', 'address', 'age', 'salary']
for field in requiredFields:
    if not form.has_key(field):
        print field


Or you might be able to do:

for name in form.keys():
    if not form[name].value:
        print name







More information about the Python-list mailing list