HTML_QuickForm_Controller
[ class tree: HTML_QuickForm_Controller ] [ index: HTML_QuickForm_Controller ] [ all elements ]

Source for file tabbed.php

Documentation is available at tabbed.php

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

Documentation generated on Mon, 11 Mar 2019 15:34:48 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.