<?php

    
require_once 'HTML/QuickForm.php';
    
    class 
signupForm extends HTML_QuickForm
    
{
        function 
signupForm()
        {
            
parent::HTML_QuickForm('signunForm');
            
            
$this->addElement('header'null'Signup');
            
$this->addElement('text''username''Username');
            
$this->addElement('password''pass1''Password');
            
$this->addElement('password''pass2''Password confirm');
            
            
// add a  group of buttons. Groups appear on one line
            
$group = array();
            
// reset buttons clear the form
            
$group[] =& $this->createElement('reset''reset''Clear Form');
            
$group[] =& $this->createElement('submit''submit''Signup');
            
$this->addGroup($group'buttons');
            
            
// require a username
            
$this->addRule('username''A username is required''required');
            
// enforce a password between 3 and 8 chars
            
$this->addRule('pass1''Your password must be between 3 and 8 chars''rangelength', array(3,8));
            
// compare the passwords
            
$this->addRule(array('pass1''pass2'), 'Your passwords don\'t match''compare');
            
            
// register and add a rule to check if a username is free
            
$this->registerRule('checkusername''callback''usernameOK', &$this);
            
$this->addRule('username''Username is taken''checkusername');
        }
        
        function 
usernameOK($username)
        {
            
// in a real world situation, you would query the database here
            // to see if the username was free
            
if ($username == 'root')
            {
                return 
false;
            }
            else
            {
                return 
true;
            }
        }
        
        function 
process()
        {
            
// this is where the new user would be saved into the database
        
}
    }
    
    
$form = new signupForm();
    if (
$form->validate())
    {
        
$form->process();
    }
    else
    {
        
$form->display();
    }
    
?>