CGI module: get form name

E

ej

I'm not seeing how to get at the 'name' attribute of an HTML <form> element.

form = cgi.FieldStorage()

gives you a dictionary-like object that has keys for the various named
elements *within* the form...

I could easily replicate the form name in a hidden field, but there ought to
be some way to get directly at the form name but I'm just not seeing it. I
looked in the os.environ() - don't see it there.

Any ideas?

Thanks! :)
 
B

Ben Cartwright

ej said:
I'm not seeing how to get at the 'name' attribute of an HTML <form> element.

form = cgi.FieldStorage()

gives you a dictionary-like object that has keys for the various named
elements *within* the form...

I could easily replicate the form name in a hidden field, but there ought to
be some way to get directly at the form name but I'm just not seeing it.

There isn't. This is a limitation of the CGI protocol, due to the way
HTTP requests work. I.e., the name attribute of <form> is *not*
included in form submissions. Regardless of whether the method is GET
or POST, it's only the fields' key/value pairs that are encoded and
sent off to the server.

If you need it, a hidden field is a good place for the form name. Or
you could use cookies.

Hope that helps,
--Ben
 
T

Tim Roberts

ej said:
I'm not seeing how to get at the 'name' attribute of an HTML <form> element.

form = cgi.FieldStorage()

gives you a dictionary-like object that has keys for the various named
elements *within* the form...

I could easily replicate the form name in a hidden field, but there ought to
be some way to get directly at the form name but I'm just not seeing it. I
looked in the os.environ() - don't see it there.

Nope, the form name is not transmitted as part of the HTTP request. It
only exists for the convenience of the client-side code (like Javascript).
 

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

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,295
Latest member
EmilG1510

Latest Threads

Top