Creating Self-Posting CGI Scripts : Form : CGI Web PYTHON TUTORIALS


PYTHON TUTORIALS » CGI Web » Form »

 

Creating Self-Posting CGI Scripts


import cgi, os, sys

sys.stderr = sys.stdout

data = cgi.FieldStorage()

formText = """Content-type: text/htmln
<title>CGI Self-Post Form</title>n
<h2>Enter Quote</h2><Paragraph>
<form method="POST" action="cgi_selfpost.cgi">
    Name <input type="TEXT" name="name">
    <paragraph>
    Quote <input type="TEXT" name="quote" size="80">
    <paragraph>
    <input type="SUBMIT" value="send">
</form>
<hr>
<h2>Received Quotes</h2><paragraph>"""
print formText

if data.has_key('name') and data.has_key('quote'):
    f = open("quotes.dat"'a')
    f.write("<li><b>%s:</b> %s</li>n" 
            (data['name'].value,
data['quote'].value))
    f.close()

f=open("quotes.dat"'r')
if f:
    print f.read()
    f.close()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo CGI Web
» Form