Get form value : CGI « Network « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Python » Network » CGI 




Get form value
 

<HTML>
<TITLE>Choose your Pizza</TITLE>
<FORM ACTION="action.py">
<H1>What size pizza would you like?</H1><BR>

<input type="radio" name="size" value="Personal"> Personal<br>
<input type="radio" name="size" value="Medium" checked> Medium<br>
<input type="radio" name="size" value="Large"> Large<BR><BR>

<H1>What kind of toppings?</H1><BR>

<INPUT TYPE=CHECKBOX NAME="mushrooms"   >mushrooms<BR>
<INPUT TYPE=CHECKBOX NAME="greenpeppers">green peppers<BR>
<INPUT TYPE=CHECKBOX NAME="olives"      >olives<BR>
<INPUT TYPE=CHECKBOX NAME="onions"      >onions<P>

How do you want to pay for it?
<select NAME="payment">
<option>Cash</option>
<option>Check</option>
<option>Credit Card</option>
</select><BR><BR>

Enter your name: <INPUT TYPE=TEXT NAME="name"><BR>
Enter your password: <INPUT TYPE=PASSWORD NAME="password"><BR><BR>


<INPUT TYPE=SUBMIT VALUE="submit">
</FORM>
</HTML>

File: action.py

#!c:/Python25/python
import cgi

def gen_html_header() :
    print "Content-Type: text/html\n\n"
    print "<HTML>"

def gen_html_trailer() :
    print "</HTML>"

form = cgi.FieldStorage()

gen_html_header()
for e in form :
    print "Received " + e + " = ["+form.getvalue(e)+"]<BR>"

   
  














Related examples in the same category
1.Sending Data to an HTML File
2.Get and set Cookies
3.Uploading Files
4.Redirection
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.