- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Passing Checkbox Data to CGI Program in Python
Checkboxes are used when more than one option is required to be selected.
Example
Here is example HTML code for a form with two checkboxes −
<form action = "/cgi-bin/checkbox.cgi" method = "POST" target = "_blank"> <input type = "checkbox" name = "maths" value = "on" /> Maths <input type = "checkbox" name = "physics" value = "on" /> Physics <input type = "submit" value = "Select Subject" /> </form>
Output
The result of this code is the following form −
Below is checkbox.cgi script to handle input given by web browser for checkbox button.
#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('maths'): math_flag = "ON" else: math_flag = "OFF" if form.getvalue('physics'): physics_flag = "ON" else: physics_flag = "OFF" print "Content-type:text/html\r\n\r\n" print "<html>" print "<head>" print "<title>Checkbox - Third CGI Program</title>" print "</head>" print "<body>" print "<h2> CheckBox Maths is : %s</h2>" % math_flag print "<h2> CheckBox Physics is : %s</h2>" % physics_flag print "</body>" print "</html>"
- Related Articles
- Passing Radio Button Data to CGI Program in Python
- Passing Text Area Data to CGI Program in Python
- Passing Drop Down Box Data to CGI Program in Python
- How to pass Checkbox Data to Python CGI script?
- First CGI Program in Python
- How to pass Radio Button Data to Python CGI script?
- How to pass Text Area Data to Python CGI script?
- How to pass Drop Down Box Data to Python CGI script?
- How to process a simple form data using Python CGI script?
- How to write Python CGI program to interact with MySQL?
- What Content-type is required to write Python CGI program?
- How to write first Hello World program using CGI programming in Python?
- How to do CGI programming in Python?
- What is CGI in Python?
- CGI Environment Variables in Python

Advertisements