# -*- coding: cp936 -*-
import web
from web import form

render = web.template.render('templates/')

urls = ('/', 'index')
app = web.application(urls, globals())

#±í¸ñ
myform = form.Form( 
    form.Textbox("boe"), 
    form.Textbox("bax", 
        form.notnull,
        form.regexp('\d+', 'Must be a digit'),#±ØÐëÎªÊý×Ö
        form.Validator('Must be more than 5', lambda x:int(x)>5)),#±ØÐë´óÓÚ5
    form.Textarea('moe'),
    form.Checkbox('curly'), 
    form.Dropdown('french', ['mustard', 'fries', 'wine'])) 

class index:
    # GETÖ±½ÓÏÔÊ¾±í¸ñ
    def GET(self): 
        form = myform()
        return render.formtest(form)

    #
    def POST(self): 
        form = myform() 
        if not form.validates(): #Êý¾ÝÓÐÐ§ÐÔ¼ì²é
            return render.formtest(form)
            #ÎÞÐ§Êý¾ÝµÄÏÔÊ¾Ò³Ãæ
            #½«form×÷Îª²ÎÊý£¬´«Èëµ½Ä£°æformtestÀïÈ¥´¦Àí¡£
        
        else:#Êý¾Ý
            return "boe: %s, bax: %s" % (form.d.boe, form['bax'].value)

if __name__=="__main__":
    web.internalerror = web.debugerror
    app.run()
