type of form field

A

Ajar

Is there any way to retrieve the type(checkbox,radio...) of the form
field from cgi.FieldStorage. I tried something like form['name'].type,
but this field seems to be None for all the form fields
 
M

Mike Meyer

Ajar said:
Is there any way to retrieve the type(checkbox,radio...) of the form
field from cgi.FieldStorage. I tried something like form['name'].type,
but this field seems to be None for all the form fields

There isn't. cgi.FieldStorage parses data sent via an HTTP
request. The type of the input element isn't part of the data sent in
an HTTP request. So not only is there no way to get it from
cgi.FieldStorage, there's no way to get it from any HTTP handling
facility, unless it gets stored somewhere outside the element in
question for you to retrieve.

While you do have to store it outside the element, you don't have to
store it outside the form. You could create a series of hidden input
elements with names "foo.type" whose value was the type of the element
foo. If your pages are dynamically generated, you could create a
dictionary mapping element names -> types, and then pickle that and
store the results in a hidden element. Or - well, I'm sure you get the
idea.

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,271
Messages
2,571,354
Members
48,042
Latest member
DoraMcBrie

Latest Threads

Top