home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / QuickForm / Page.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  6.0 KB  |  211 lines

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