import re, urllib

# From "User-Friendly Form Validation with PHP and CSS" at
# http://www.onlamp.com/pub/a/php/2004/04/22/php_css_forms.html

# This is an alternate version that matches PSE's development model.

message    = ""
emailclass = "basictext"
username   = ""

if pse.form.has_key('process'):

    pattern = r'.*@.*\..*'
    email   = pse.form['email']
    urlname = urllib.quote(pse.form['name'])

    if re.match(pattern, email):
        # Here's where you would store
        # the data in a database...
        pse.plugins.response.redirect('thankyou.pt?&username=%s' % urlname)

    message    = "Please enter a valid email address."
    username   = pse.form['name']
    emailclass = "errortext"