<!-- 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 a re-implementation using Python and PSE for comparison. -->

<?
import re, urllib

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"
?>

<html>
<style>
    .basictext {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px; color:#000066;
    }
    .errortext {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px; color:#C00000; font-weight: bold;
    }
</style>
<body>
<form action="email.pt" method="post">
    <? if message != "":
           print '<span class="errortext">%s<span><br>' % message
    ?>
    <span class="=emailclass">
        Email address:</span>
    <input name="email" type="text"
        class="=emailclass"><br>

    <span class="basictext">Your name:</span>
    <input name="name" type="text" class="basictext"
        value="=username"><br>
    <input type="hidden" name="process" value="1">
    <input type="submit" name="Button1" value="Sign up!">
</form>
</body></html>