Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset
Comments Off

CGI: Envoyer les données d’un formulaire HTML

 set, html
{filelink=16693}

#!c:/Python32/python
 
import cgi
 
def send_form( dic ) :
    Nom = dic.getvalue("nom", "" )
    PNom = dic.getvalue("prenom", "" )
 
    flag = int( dic.getvalue("flag", "0") )
 
    print "
<form action='signup.py'>"
    if flag == 1 and Nom == "" :
        print "
 
<font size=16 color='Blue'>Tapez Votre Nom:</FONT>
 
"
    else :
        print "
 
Tapez Votre Nom:
 
"
 
    if Nom != "" :
        print "
<input type='text' name='nom' value="+Nom+" size='40'>"
    else :
        print "
<input type='text' name='nom' size='40'>"
 
    if flag == 1 and PNom == "" :
        print "
 
<font size=16 color='Blue'>Tapez Votre Prénom:</FONT>
 
"
    else :
        print "
 
Tapez Votre Prénom:
 
"
    if PNom != "" :
        print "
<input type='text' name='prenom' value="+PNom+" size='40'>"
    else :
        print "
<input type='text' name='prenom' size='40'>"
    print "
 
"
    print "
<input type='submit' value='Envoyer'>"
    print "
<input type='reset'>"
    print "
<input type='hidden' name='flag' value='1'>"
    print "
 
"
 
def verif_form( dic ) :
 
    error = 0
 
    Nom = dic.getvalue("nom", "" )
    PNom = dic.getvalue("prenom", "" )
 
    if Nom == "" or PNom == "" :
        error = 1
 
    if error == 0 :
        print "Bienvenu " + Nom + " " + PNom
    return error
 
print "Content-Type: text/html"
print "<HTML>"
form = cgi.FieldStorage()
res = verif_form(form)
if res == 1:
    send_form(form)
print "
<form>"
print "</html>"

Livres Sur ce Sujet

----------------------------------------------------------------------------

Comments are closed.