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

  1. <?php
  2. /**
  3.  * Example 1 for HTML_QuickForm_Controller: using the Controller
  4.  * infrastructure to create and process the basic single-page form
  5.  * 
  6.  * $Id: simple.php,v 1.2 2003/10/02 12:49:38 avb Exp $
  7.  */
  8.  
  9. require_once 'HTML/QuickForm/Controller.php';
  10.  
  11. // Load some default action handlers
  12. require_once 'HTML/QuickForm/Action/Submit.php';
  13. require_once 'HTML/QuickForm/Action/Display.php';
  14.  
  15.  
  16. class SimplePage extends HTML_QuickForm_Page
  17. {
  18.     function buildForm()
  19.     {
  20.         $this->_formBuilt = true;
  21.  
  22.         $this->addElement('header',     null, 'Controller example 1: a simple form');
  23.         $this->addElement('text',       'tstText', 'Please enter something:', array('size'=>20, 'maxlength'=>50));
  24.         // Bind the button to the 'submit' action
  25.         $this->addElement('submit',     $this->getButtonName('submit'), 'Send');
  26.  
  27.         $this->applyFilter('tstText', 'trim');
  28.         $this->addRule('tstText', 'Pretty please!', 'required');
  29.  
  30.         $this->setDefaultAction('submit');
  31.     }
  32. }
  33.  
  34.  
  35. class ActionProcess extends HTML_QuickForm_Action
  36. {
  37.     function perform(&$page, $actionName)
  38.     {
  39.         echo "Submit successful!<br>\n<pre>\n";
  40.         var_dump($page->exportValues());
  41.         echo "\n</pre>\n";
  42.     }
  43. }
  44.  
  45. $page =& new SimplePage('page1');
  46.  
  47. // We actually add these handlers here for the sake of example
  48. // They can be automatically loaded and added by the controller
  49. $page->addAction('display', new HTML_QuickForm_Action_Display());
  50. $page->addAction('submit', new HTML_QuickForm_Action_Submit());
  51.  
  52. // This is the action we should always define ourselves
  53. $page->addAction('process', new ActionProcess());
  54.  
  55. $controller =& new HTML_QuickForm_Controller('simpleForm');
  56. $controller->addPage($page);
  57. $controller->run();
  58. ?>
  59.