#!/usr/bin/python
#=====================================================================================
# Generic responder for any html form 
#=====================================================================================
import HTTPparam

print("Content-Type: text/html \n")          #required cgi header

print('''                                                
    <html>
    <head>
    <title>Sample Python Forms-responder</title>
    </head>
    <body>
    <b>The Transmitted HTML form elements are...</b>
    <p>
''')                                                     

print('''     
    <table border=2>
    <tr bgcolor=tan>
    <th>Element Name</th><th>Element Value</th>
''')  

#-------------------------------------------------------------------------------------
# Generic loop to access all form elements
#-------------------------------------------------------------------------------------
def printElements():                        #define a function

    elements = HTTPparam.getAll()           #obtain all http parameter names/values
    for (name,value) in elements.items():    
        print('<tr><th>', name, '<td>', value, end='') 
  
#-------------------------------------------------------------------------------------
        
printElements()                         #call the function

print('</table>')
print('</body>')
print('</html>')

    

#=== link to see the python code =================================================
import os, sys
sys.path.insert(0,'/home/staff/sultan/public_html/cgi-bin/python')
import zCode                          #import func to display the Python code
filename = os.path.abspath(__file__)  #get absolute file name 
zCode.display(filename)               #call it
#=================================================================================