cgi form handler question
jmdeschamps
jmdeschamps at cvm.qc.ca
Mon Apr 7 09:22:02 EDT 2003
Peter Hansen <peter at engcorp.com> wrote in message news:<3E9158CA.C53791E5 at engcorp.com>...
> 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
...left empty, -unless you use the form
cgi.FieldStorage(keep_blank_values = 1) to get your form info as in
http://www.python.org/doc/current/lib/node297.html
and as someone else might have said, 'Happy CGI-ing',
Jean-Marc
More information about the Python-list
mailing list