cgi parameters

python at joramo.com python at joramo.com
Thu Dec 28 18:07:50 CET 2000


> I need to pass index parameter to script executed by post method (via
> form)

> <form action="newpost.cgi?index=1" method="post">

The way that you are trying to pass a parameter will not work for forms;
although it will work for links such as:

<a href="newpost.cgi?index=1">Click Me!</a>


To pass parameters via a form, you need to include the parameter withing an
<input> tag. If You do not want to allow the client to modify the value of the
parameter you need to use a 'hidden' input tag. For example:

<form action="newpost.cgi method="get">
  <input type=hidden name='index' value='1'>
  <input type=submit>
</form>


Of course, just because the parameters are hidden does not mean that a web
user that knows HTML could not rewrite the page and submit their own values.
So you still need to validate the data.

Now that should solve your problem. However, what if you really need to use
the method that you were originally attempting? Retarget your form action to
the following short python script:

!/usr/bin/python
import cgi
print cgi.test()


This will display a wealth of information about the shell and web server
environment. (And this little script will come in handy for debugging many
form/CGI problems.) I ran this script on my system and after examining the
results I found the following entry:

REQUEST_URI
   /cgi-bin/nickads/testform.py?index=1

Within a python script this could be accessed via:

import os
request_uri = os.environ['REQUEST_URI']


It is important to note that while your server may not call this value
"REQUEST_URI". Or it may provide an environmental variable
containing just "?index=1" which would simplify parsing a bit.


--
Lee A. Joramo                      ljoramo at nickads.com
The Nickel Want Ads                www.nickads.com
Internet Manager                   970-242-5555



Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list