<?php

    
require_once 'HTML/QuickForm.php';
    require_once 
'Savant2.php';
    require_once 
'./Savant.php';
        
    class 
signupForm extends HTML_QuickForm
    
{
        function 
signupForm()
        {
            
parent::HTML_QuickForm('signupForm');
            
            
$this->addElement('header''signup''Signup');
            
$this->addElement('text''username''Username');
            
$this->addElement('password''pass1''Password');
            
$this->addElement('password''pass2''Password confirm');
            

            
$this->setDefaults(array('username' => 'test'));
            
// 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');
            
$this->addRule('pass1''A password 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;
            }
        }
        
    }
    
    
$template = ($_SERVER['PATH_INFO']=='/static')?'qf_savant_static.tpl.php':'qf_savant_dynamic.tpl.php';

    
$renderer =& new HTML_QuickForm_Renderer_Savant();
        
    
$form = new signupForm();
    
$form->validate();
    
$form->accept($renderer);
    
    
$tpl = new Savant2();
    
$tpl->assign('form'$renderer->toArray());
    
$tpl->display($template);
    
?>