Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
TABLE 22.2 HTML Form Elements

To build the form in your webpage, you must use the HTML

element, which defines the
action the browser takes with the form data when the site visitor clicks the Submit button for the form.
You use this element to tell your Python script where to pass the form data. Listing 22.4 shows the
script2207.html file, which creates a simple web form you can use to use to test the
element.


LISTING 22.4 Creating a Simple Web Form


Click here to view code image


1: <!DOCTYPE html>
2: <html>
3: <head>
4: <title>Web Form Test</title>
5: </head>
6: <body>
7: <h2>Please enter your information</h2>
8: <br />
9: <form action='/cgi-bin/script2208.cgi' method='post'>
10: <label>Last Name:</label><input type="text" name="lname" size="30" />
11: <br />
12: <label>First Name:</label><input type="text" name="fname" size="30" />
13: <br />
14: <label>Age range:</label><br />
15: <input type="radio" name="age" value="20-30" /> 20-30<br />
16: <input type="radio" name="age" value="31-40" /> 31-40<br />
17: <input type="radio" name="age" value="41-50" /> 41-50<br />
18: <input type="radio" name="age" value="51+" /> 51+<br />
19: <br />
20: <label>Select all that apply:</label><br />
21: <input type="checkbox" name="hobbies" value="fishing" /> Fishing<br />
22: <input type="checkbox" name="hobbies" value="golf" /> Golf<br />
23: <input type="checkbox" name="hobbies" value="baseball" /> Baseball<br />
24: <input type="checkbox" name="hobbies" value="football" /> Football<br />
25: <br />
26: <label>Enter your comment:</label><br />
27: <textarea name="comment" rows="10" cols="20"></textarea>
28: <br />
29: <input type="submit" value="Submit your comment" />
30: </form>
31: </body>
32: </html>
Free download pdf