Python CGI - form 1
#!/usr/bin/python
import cgi
def hlavicka(text): # hlavicka HTML stranky
print "<html>"
print "<head>"
print "<title>", text, "</title>"
print "</HEAD>"
print "<body bgcolor = white>"
def paticka(): # paticka HTML stranky
print "</body>"
print "</html>"
def formular(): # vytvori vstupni fromular
hlavicka("cgi demo 02 / formular")
print "<h3>Zadejte jmeno a heslo</h3>"
print "<form method=post action='cgi-demo-02.py'>"
print "<table border=0>"
print "<tr><th>Jmeno:</th><td><input type=text name='username'></td></tr>"
print "<tr><th>Heslo:</th><td><input type=password name='password'></td></tr>"
print "</table>"
print "<input type=hidden name='action' value='display'>"
print "<input type=submit value='Zadej'>"
print "</form>"
paticka()
def stranka(jmeno, heslo):
hlavicka("cgi demo 02 / HTML stranka")
print "Zadal jsi jmeno ", jmeno
print " a heslo ", heslo
paticka()
def main():
print "Content-type: text/html"
print
form = cgi.FieldStorage()
if (form.has_key("action") and form.has_key("username") \
and form.has_key("password")):
stranka(form["username"].value, form["password"].value)
else:
formular()
main()
[ Zpět ]