cgi form handler question
Peter Hansen
peter at engcorp.com
Mon Apr 7 06:54:02 EDT 2003
Ian Bicking wrote:
>
> > the user forgets to input his email and age
> > how would i write a for loop to output:
> >
> > email
> > age
>
> 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
The latter suggestion won't usually work, as the data sent
from the browser does not even contain the names of the fields
which are left empty.
-Peter
More information about the Python-list
mailing list