home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / tabbed.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  6.4 KB  |  171 lines

  1. <?php
  2. /**
  3.  * Example 3 for HTML_QuickForm_Controller: Tabbed form
  4.  * 
  5.  * $Id: tabbed.php,v 1.2 2003/10/02 12:49:38 avb Exp $
  6.  */
  7.  
  8. require_once 'HTML/QuickForm/Controller.php';
  9.  
  10. // Load some default action handlers
  11. require_once 'HTML/QuickForm/Action/Submit.php';
  12. require_once 'HTML/QuickForm/Action/Jump.php';
  13. require_once 'HTML/QuickForm/Action/Display.php';
  14. require_once 'HTML/QuickForm/Action/Direct.php';
  15.  
  16. session_start();
  17.  
  18. class PageFoo extends HTML_QuickForm_Page
  19. {
  20.     function buildForm()
  21.     {
  22.         $this->_formBuilt = true;
  23.  
  24.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('foo'), 'Foo', array('class' => 'flat', 'disabled' => 'disabled'));
  25.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('bar'), 'Bar', array('class' => 'flat'));
  26.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('baz'), 'Baz', array('class' => 'flat'));
  27.         $this->addGroup($tabs, 'tabs', null, ' ', false);
  28.         
  29.         $this->addElement('header',     null, 'Foo page');
  30.  
  31.         $radio[] = &$this->createElement('radio', null, null, 'Yes', 'Y');
  32.         $radio[] = &$this->createElement('radio', null, null, 'No', 'N');
  33.         $radio[] = &$this->createElement('radio', null, null, 'Maybe', 'M');
  34.         $this->addGroup($radio, 'iradYesNoMaybe', 'Do you want this feature?', '<br />');
  35.  
  36.         $this->addElement('text',       'tstText', 'Why do you want it?', array('size'=>20, 'maxlength'=>50));
  37.  
  38.         $this->addElement('submit',     $this->getButtonName('submit'), 'Big Red Button', array('class' => 'bigred'));
  39.  
  40.         $this->addRule('iradYesNoMaybe', 'Check a radiobutton', 'required');
  41.  
  42.         $this->setDefaultAction('submit');
  43.     }
  44. }
  45.  
  46. class PageBar extends HTML_QuickForm_Page
  47. {
  48.     function buildForm()
  49.     {
  50.         $this->_formBuilt = true;
  51.  
  52.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('foo'), 'Foo', array('class' => 'flat'));
  53.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('bar'), 'Bar', array('class' => 'flat', 'disabled' => 'disabled'));
  54.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('baz'), 'Baz', array('class' => 'flat'));
  55.         $this->addGroup($tabs, 'tabs', null, ' ', false);
  56.         
  57.         $this->addElement('header',     null, 'Bar page');
  58.  
  59.         $this->addElement('date',       'favDate', 'Favourite date:', array('format' => 'd-M-Y', 'minYear' => 1950, 'maxYear' => date('Y')));
  60.         $checkbox[] = &$this->createElement('checkbox', 'A', null, 'A');
  61.         $checkbox[] = &$this->createElement('checkbox', 'B', null, 'B');
  62.         $checkbox[] = &$this->createElement('checkbox', 'C', null, 'C');
  63.         $checkbox[] = &$this->createElement('checkbox', 'D', null, 'D');
  64.         $checkbox[] = &$this->createElement('checkbox', 'X', null, 'X');
  65.         $checkbox[] = &$this->createElement('checkbox', 'Y', null, 'Y');
  66.         $checkbox[] = &$this->createElement('checkbox', 'Z', null, 'Z');
  67.         $this->addGroup($checkbox, 'favLetter', 'Favourite letters:', array(' ', '<br />'));
  68.  
  69.         $this->addElement('submit',     $this->getButtonName('submit'), 'Big Red Button', array('class' => 'bigred'));
  70.  
  71.         $this->setDefaultAction('submit');
  72.     }
  73. }
  74.  
  75. class PageBaz extends HTML_QuickForm_Page
  76. {
  77.     function buildForm()
  78.     {
  79.         $this->_formBuilt = true;
  80.  
  81.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('foo'), 'Foo', array('class' => 'flat'));
  82.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('bar'), 'Bar', array('class' => 'flat'));
  83.         $tabs[] =& $this->createElement('submit',   $this->getButtonName('baz'), 'Baz', array('class' => 'flat', 'disabled' => 'disabled'));
  84.         $this->addGroup($tabs, 'tabs', null, ' ', false);
  85.         
  86.         $this->addElement('header',     null, 'Baz page');
  87.  
  88.         $this->addElement('textarea',   'textPoetry', 'Recite a poem:', array('rows' => 5, 'cols' => 40));
  89.         $this->addElement('textarea',   'textOpinion', 'Did you like this demo?', array('rows' => 5, 'cols' => 40));
  90.  
  91.         $this->addElement('submit',     $this->getButtonName('submit'), 'Big Red Button', array('class' => 'bigred'));
  92.  
  93.         $this->addRule('textPoetry', 'Pretty please!', 'required');
  94.  
  95.         $this->setDefaultAction('submit');
  96.     }
  97. }
  98.  
  99. // We subclass the default 'display' handler to customize the output
  100. class ActionDisplay extends HTML_QuickForm_Action_Display
  101. {
  102.     function _renderForm(&$page) 
  103.     {
  104.         $renderer =& $page->defaultRenderer();
  105.         // Do some cheesy customizations
  106.         $renderer->setElementTemplate("\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\" colspan=\"2\">{element}</td>\n\t</tr>", 'tabs');
  107.         $renderer->setFormTemplate(<<<_HTML
  108. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  109. <html>
  110. <head>
  111. <title>Controller example 3: tabbed form</title>
  112. <style type="text/css">
  113. input.bigred {font-weight: bold; background: #FF6666;}
  114. input.flat {border-style: solid; border-width: 2px; border-color: #000000;}
  115. </style>
  116. </head>
  117.  
  118. <body>
  119. <form{attributes}>
  120. <table border="0">
  121. {content}
  122. </table>
  123. </form>
  124. </body>
  125. </html>
  126. _HTML
  127. );
  128.         $page->display();
  129.     }
  130. }
  131.  
  132. class ActionProcess extends HTML_QuickForm_Action
  133. {
  134.     function perform(&$page, $actionName)
  135.     {
  136.         echo "Submit successful!<br>\n<pre>\n";
  137.         var_dump($page->controller->exportValues());
  138.         echo "\n</pre>\n";
  139.     }
  140. }
  141.  
  142. $tabbed =& new HTML_QuickForm_Controller('Tabbed', false);
  143.  
  144. $tabbed->addPage(new PageFoo('foo'));
  145. $tabbed->addPage(new PageBar('bar'));
  146. $tabbed->addPage(new PageBaz('baz'));
  147.  
  148. // These actions manage going directly to the pages with the same name
  149. $tabbed->addAction('foo', new HTML_QuickForm_Action_Direct());
  150. $tabbed->addAction('bar', new HTML_QuickForm_Action_Direct());
  151. $tabbed->addAction('baz', new HTML_QuickForm_Action_Direct());
  152.  
  153. // We actually add these handlers here for the sake of example
  154. // They can be automatically loaded and added by the controller
  155. $tabbed->addAction('jump', new HTML_QuickForm_Action_Jump());
  156. $tabbed->addAction('submit', new HTML_QuickForm_Action_Submit());
  157.  
  158. // The customized actions
  159. $tabbed->addAction('display', new ActionDisplay());
  160. $tabbed->addAction('process', new ActionProcess());
  161.  
  162. $tabbed->setDefaults(array(
  163.     'iradYesNoMaybe' => 'M',
  164.     'favLetter'      => array('A' => true, 'Z' => true),
  165.     'favDate'        => array('d' => 1, 'M' => 1, 'Y' => 2001),
  166.     'textOpinion'    => 'Yes, it rocks!'
  167. ));
  168.  
  169. $tabbed->run();
  170. ?>
  171.