<?php
/**
 * Example 1 for HTML_QuickForm_Controller: using the Controller
 * infrastructure to create and process the basic single-page form
 * 
 * $Id: simple.php,v 1.2 2003/10/02 12:49:38 avb Exp $
 */

require_once './pear/HTML/QuickForm/Controller.php';

// Load some default action handlers
require_once './pear/HTML/QuickForm/Action/Submit.php';
require_once './pear/HTML/QuickForm/Action/Display.php';


class SimplePage extends HTML_QuickForm_Page
{
    function buildForm()
    {
        $this->_formBuilt = true;

        $this->addElement('header',     null, 'Controller example 1: a simple form');
        $this->addElement('text',       'tstText', 'Please enter something:', array('size'=>20, 'maxlength'=>50));
        // Bind the button to the 'submit' action
	//$check[] = $this->addElement('checkbox','1',null,'1');
// Creates a checkboxes group using an array of separators
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '1',null, 'A',array("value"=>'you fucking cunt'));
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '2', null, 'B');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '3', null, 'C');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '4', null, 'D');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '5', null, 'e');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '6', null, 'f')	;
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '7', null, 'g');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '8', null, 'h');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '9', null, 'i');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '10', null, 'j');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '11', null, 'k');
	$checkbox[] = &HTML_QuickForm::createElement('checkbox', '12', null, 'l');
	$this->addGroup($checkbox,'checkbox','<br>');
        $this->addElement('submit',     $this->getButtonName('submit'), 'Send');

        $this->applyFilter('tstText', 'trim');
        //$this->addRule('tstText', 'Pretty please!', 'required');

        $this->setDefaultAction('submit');
    }
}


class ActionProcess extends HTML_QuickForm_Action
{
    function perform(&$page, $actionName)
    {
        echo "Submit successful!<br>\n<pre>\n";
        var_dump($page->exportValues());
        echo "\n</pre>\n";
    }
}

$page =& new SimplePage('page1');

// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
$page->addAction('display', new HTML_QuickForm_Action_Display());
$page->addAction('submit', new HTML_QuickForm_Action_Submit());

// This is the action we should always define ourselves
$page->addAction('process', new ActionProcess());

$controller =& new HTML_QuickForm_Controller('simpleForm');
$controller->addPage($page);
$controller->run();
?>
