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

Source for file Page.php

Documentation is available at Page.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Alexey Borzov <avb@php.net>                                 |
  17. // |          Bertrand Mansion <bmansion@mamasam.com>                     |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: Page.php 6184 2005-09-07 10:08:17Z bmol $
  21.  
  22. require_once 'HTML/QuickForm.php';
  23.  
  24. /**
  25.  * The class represents a page of a multipage form.
  26.  * 
  27.  * Generally you'll need to subclass this and define your buildForm()
  28.  * method that will build the form. While it is also possible to instantiate
  29.  * this class and build the form manually, this is not the recommended way.
  30.  * 
  31.  * @author  Alexey Borzov <avb@php.net>
  32.  * @package HTML_QuickForm_Controller
  33.  * @version $Revision: 6184 $
  34.  */
  35. {
  36.    /**
  37.     * Contains the mapping of actions to corresponding HTML_QuickForm_Action objects
  38.     * @var array 
  39.     */
  40.     var $_actions = array();
  41.  
  42.    /**
  43.     * Contains a reference to a Controller object containing this page
  44.     * @var object HTML_QuickForm_Controller 
  45.     * @access public
  46.     */
  47.     var $controller = null;
  48.  
  49.    /**
  50.     * Should be set to true on first call to buildForm()
  51.     * @var bool 
  52.     */
  53.     var $_formBuilt = false;
  54.  
  55.    /**
  56.     * Class constructor
  57.     * 
  58.     * @access public
  59.     */
  60.     function HTML_QuickForm_Page($formName$method 'post'$target '_self'$attributes null)
  61.     {
  62.         $this->HTML_QuickForm($formName$method''$target$attributes);
  63.     }
  64.  
  65.  
  66.    /**
  67.     * Registers a handler for a specific action.
  68.     * 
  69.     * @access public
  70.     * @param  string    name of the action
  71.     * @param  object HTML_QuickForm_Action   the handler for the action
  72.     */
  73.     function addAction($actionName&$action)
  74.     {
  75.         $this->_actions[$actionName=$action;
  76.     }
  77.  
  78.  
  79.    /**
  80.     * Handles an action.
  81.     * 
  82.     * If an Action object was not registered here, controller's handle()
  83.     * method will be called.
  84.     * 
  85.     * @access public
  86.     * @param  string Name of the action
  87.     */
  88.     function handle($actionName)
  89.     {
  90.         if (isset($this->_actions[$actionName])) {
  91.             return $this->_actions[$actionName]->perform($this$actionName);
  92.         else {
  93.             return $this->controller->handle($this$actionName);
  94.         }
  95.     }
  96.  
  97.  
  98.    /**
  99.     * Returns a name for a submit button that will invoke a specific action.
  100.     * 
  101.     * @access public
  102.     * @param  string  Name of the action
  103.     * @return string  "name" attribute for a submit button
  104.     */
  105.     function getButtonName($actionName)
  106.     {
  107.         return '_qf_' $this->getAttribute('id''_' $actionName;
  108.     }
  109.  
  110.  
  111.    /**
  112.     * Loads the submit values from the array.
  113.     * 
  114.     * The method is NOT intended for general usage.
  115.     * 
  116.     * @param array  'submit' values
  117.     * @access public
  118.     */
  119.     function loadValues($values)
  120.     {
  121.         $this->_submitValues = $values;
  122.         foreach (array_keys($this->_elementsas $key{
  123.             $this->_elements[$key]->onQuickFormEvent('updateValue'null$this);
  124.         }
  125.     }
  126.  
  127.  
  128.    /**
  129.     * Builds a form.
  130.     * 
  131.     * You should override this method when you subclass HTML_QuickForm_Page,
  132.     * it should contain all the necessary addElement(), applyFilter(), addRule()
  133.     * and possibly setDefaults() and setConstants() calls. The method will be
  134.     * called on demand, so please be sure to set $_formBuilt property to true to
  135.     * assure that the method works only once.
  136.     * 
  137.     * @access public
  138.     * @abstract
  139.     */
  140.     function buildForm()
  141.     {
  142.         $this->_formBuilt = true;
  143.     }
  144.  
  145.  
  146.    /**
  147.     * Checks whether the form was already built.
  148.     * 
  149.     * @access public
  150.     * @return bool 
  151.     */
  152.     function isFormBuilt()
  153.     {
  154.         return $this->_formBuilt;
  155.     }
  156.  
  157.  
  158.    /**
  159.     * Sets the default action invoked on page-form submit
  160.     * 
  161.     * This is necessary as the user may just press Enter instead of
  162.     * clicking one of the named submit buttons and then no action name will
  163.     * be passed to the script.
  164.     * 
  165.     * @access public
  166.     * @param  string    default action name
  167.     */
  168.     function setDefaultAction($actionName)
  169.     {
  170.         if ($this->elementExists('_qf_default')) {
  171.             $element =$this->getElement('_qf_default');
  172.             $element->setValue($this->getAttribute('id'':' $actionName);
  173.         else {
  174.             $this->addElement('hidden''_qf_default'$this->getAttribute('id'':' $actionName);
  175.         }
  176.     }
  177. }
  178.  
  179. ?>

Documentation generated on Thu, 12 Jun 2008 14:09:49 -0500 by phpDocumentor 1.4.1