I've been trying the hidden field, but the problem is that when I set the variable flag, it stays in memory. I would rather just pass a var like I've been trying, but I don't think it's possible. Any ideas? Is a session cookie the only way? Here's more simplified code:
#!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) import MySQLdb import string, re def client(): form = cgi.FieldStorage() client = string.replace(string.replace(form.getfirst('client', ''), "'", '''), '"', '"') flag = form.getfirst('flag', '') print "Content-Type: text/html" print print """ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <head xmlns="http://www.w3.org/1999/xhtml"> <body> """ if flag == '': print """ <form method="post" action="client.py"> Company Name: <input type='text' value='' size='20' maxlength='100' name='client' /><br /> <input type='hidden' name='flag' value='y' /> <div align='center'> <input type='submit' value=' Send ' /> </div> </form> </body></html> """ else: host = 'h' db = 'db' user = 'u' passwd = '1' database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('insert into companies (client);' % (client)) cursor.close() print '</body></html>' client() TIA, V On Tue, Sep 22, 2009 at 1:43 PM, Dennis Lee Bieber <wlfr...@ix.netcom.com>wrote: > On Tue, 22 Sep 2009 12:50:31 -0400, Victor Subervi > <victorsube...@gmail.com> declaimed the following in > gmane.comp.python.general: > > > Well it's Web stuff, sure, but it's written in python :) The code > follows. > > The problem is that I haven't figured out how to tell the program that > the > > user has entered data and to clear the cache of that data so that it's > not > > re-entered. How do I do that? > > Remember, HTTP is a stateless protocol. EACH submission is > considered a totally new transaction with no memory of the previous > processing. > > Possible solutions... > > * Use a session cookie that identifies what phase in the multistep > processing you are in... > > * Use a hidden field in the form that defaults to, say "False", when > you first display the form, but then gets set to "True" during the first > response process (and is then sent back out with "True" so the second > response takes a different branch). > > -- > Wulfraed Dennis Lee Bieber KD6MOG > wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list