File:demo.py#!c:/Python25/pythonimport cgidef send_form( dic ) : fName = dic.getvalue("firstname", "" ) lName = dic.getvalue("lastname", "" ) flag = int( dic.getvalue("flag", "0") ) print "" if flag == 1 and fName == "" : print "Enter your first name:" else : print "Enter your first name:" if fName != "" : print "" else : print "" if flag == 1 and lName == "" : print "Enter your last name:" else : print "Enter your last name:" if lName != "" : print "" else : print "" print "" print "" print "" print "" print ""def gen_output( dic ) : error = 0 fName = dic.getvalue("firstname", "" ) lName = dic.getvalue("lastname", "" ) if fName == "" or lName == "" : error = 1 if error == 0 : print "Hello there " + fName + " " + lName return errorprint "Content-Type: text/html\n\n"print ""form = cgi.FieldStorage()res = gen_output(form)if res == 1: send_form(form)print ""print ""
Enter your first name:
Enter your last name:
" print "" print "" print "" print "