Dynamic Form

BJ Swope bigblueswope at gmail.com
Wed Sep 23 21:13:17 EDT 2009


What is your code not doing?

Are you winding up with duplicate data in the DB?

Is your web browser re-submitting the form with the same data if you refresh
the screen?

Is your web browser pre-filling the fields of the form due to caching?

I don't understand what's not working

On Wed, Sep 23, 2009 at 12:40 PM, Victor Subervi <victorsubervi at gmail.com>wrote:

> 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 <wlfraed at ix.netcom.com>wrote:
>
>> On Tue, 22 Sep 2009 12:50:31 -0400, Victor Subervi
>> <victorsubervi at 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
>>        wlfraed at ix.netcom.com   HTTP://wlfraed.home.netcom.com/
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
To argue that honorable conduct is only required against an honorable enemy
degrades the Americans who must carry out the orders. -- Charles Krulak,
Former Commandant of the Marine Corps

We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090923/f2a934c9/attachment.html>


More information about the Python-list mailing list