0

I've got a simple page here, titled login.py for the time being since eventually it will be a functional login page. However, right now I've got it set up to try to get POST variables from the form being submitted. This is the code I have so far:

from mod_python import apache, Session, util
from time import time
import webout

def index(req):
        form = util.FieldStorage(req)
        testval = form.getfirst("test")
        return webout.htmlout("", """
        <form name="login" action="login.py" method="post">
                <h2>%s</h2>
                <p>Enter something:</p><input type="text" name="test">
                <input type="submit" value="Submit">
        </form>
""" % testval)

Webout is a module I wrote, essentially all it does is return a properly formatted HTML output so I don't have to type it out all the time, calling htmlout I am passing in what would go in the head and body.

Anyway, if I were to change the form's method to get, the h2 properly displays whatever I submit in the text box in the form. However, if I change it to post, I get None (so I'm assuming null). What else do I have to do to reference POST variables?

Skyline969
  • 431
  • 2
  • 7
  • 17

1 Answers1

0

I've figured out one way to do it, although I'm not sure if it's the best way to do it. The modified code is as follows:

from mod_python import apache, Session, util
from time import time
import webout

def index(req, test=""):
        form = util.FieldStorage(req)
        #testval = form.getfirst("test")
        return webout.htmlout("", """
        <form name="login" action="login.py" method="post">
                <p>%s</p><br/>
                <p>Enter something:</p><input type="text" name="test">
                <input type="submit" value="Submit">
        </form>
""" % test)

So basically, POST passes the variables to the index method. Assign default values in case you're coming there not from a form submit. This works for both POST and GET.

Skyline969
  • 431
  • 2
  • 7
  • 17