How to pass Radio Button Data to Python CGI script?

Passing Radio Button Data to CGI Program

Radio Buttons are used when only one option is required to be selected.

Here is example HTML code for a form with two radio buttons −


Maths Physics

The result of this code is the following form −

 Maths  Physics Select Subject

Below is radiobutton.py script to handle input given by web browser for radio 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('subject'):
   subject = form.getvalue('subject')
else:
   subject = "Not set"
print "Content-type:text/html\r\n\r\n"
print ""
print ""
print "Radio - Fourth CGI Program"
print ""
print ""
print "

Selected Subject is %s

" % subject print "" print ""
Updated on: 2020-06-16T12:16:41+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements