Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP version 4.0                                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997, 1998, 1999, 2000, 2001 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: Adam Daniel <adaniel1@eesus.jnj.com>                        |
  17  // |          Bertrand Mansion <bmansion@mamasam.com>                     |
  18  // +----------------------------------------------------------------------+
  19  //
  20  // $Id$
  21  
  22  require_once("HTML/QuickForm/element.php");
  23  
  24  /**
  25   * Base class for input form elements
  26   * 
  27   * @author       Adam Daniel <adaniel1@eesus.jnj.com>
  28   * @author       Bertrand Mansion <bmansion@mamasam.com>
  29   * @version      1.0
  30   * @since        PHP4.04pl1
  31   * @access       public
  32   * @abstract
  33   */
  34  class HTML_QuickForm_input extends HTML_QuickForm_element
  35  {
  36      // {{{ constructor
  37  
  38      /**
  39       * Class constructor
  40       * 
  41       * @param    string     Input field name attribute
  42       * @param    mixed      Label(s) for the input field
  43       * @param    mixed      Either a typical HTML attribute string or an associative array
  44       * @since     1.0
  45       * @access    public
  46       * @return    void
  47       */
  48      public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
  49          parent::__construct($elementName, $elementLabel, $attributes);
  50      } //end constructor
  51  
  52      /**
  53       * Old syntax of class constructor. Deprecated in PHP7.
  54       *
  55       * @deprecated since Moodle 3.1
  56       */
  57      public function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null) {
  58          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  59          self::__construct($elementName, $elementLabel, $attributes);
  60      }
  61  
  62      // }}}
  63      // {{{ setType()
  64  
  65      /**
  66       * Sets the element type
  67       *
  68       * @param     string    $type   Element type
  69       * @since     1.0
  70       * @access    public
  71       * @return    void
  72       */
  73      function setType($type)
  74      {
  75          $this->_type = $type;
  76          $this->updateAttributes(array('type'=>$type));
  77      } // end func setType
  78      
  79      // }}}
  80      // {{{ setName()
  81  
  82      /**
  83       * Sets the input field name
  84       * 
  85       * @param     string    $name   Input field name attribute
  86       * @since     1.0
  87       * @access    public
  88       * @return    void
  89       */
  90      function setName($name)
  91      {
  92          $this->updateAttributes(array('name'=>$name));
  93      } //end func setName
  94      
  95      // }}}
  96      // {{{ getName()
  97  
  98      /**
  99       * Returns the element name
 100       * 
 101       * @since     1.0
 102       * @access    public
 103       * @return    string
 104       */
 105      function getName()
 106      {
 107          return $this->getAttribute('name');
 108      } //end func getName
 109      
 110      // }}}
 111      // {{{ setValue()
 112  
 113      /**
 114       * Sets the value of the form element
 115       *
 116       * @param     string    $value      Default value of the form element
 117       * @since     1.0
 118       * @access    public
 119       * @return    void
 120       */
 121      function setValue($value)
 122      {
 123          $this->updateAttributes(array('value'=>$value));
 124      } // end func setValue
 125  
 126      // }}}
 127      // {{{ getValue()
 128  
 129      /**
 130       * Returns the value of the form element
 131       *
 132       * @since     1.0
 133       * @access    public
 134       * @return    string
 135       */
 136      function getValue()
 137      {
 138          return $this->getAttribute('value');
 139      } // end func getValue
 140      
 141      // }}}
 142      // {{{ toHtml()
 143  
 144      /**
 145       * Returns the input field in HTML
 146       * 
 147       * @since     1.0
 148       * @access    public
 149       * @return    string
 150       */
 151      function toHtml()
 152      {
 153          if ($this->_flagFrozen) {
 154              return $this->getFrozenHtml();
 155          } else {
 156              return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
 157          }
 158      } //end func toHtml
 159  
 160      // }}}
 161      // {{{ onQuickFormEvent()
 162  
 163      /**
 164       * Called by HTML_QuickForm whenever form event is made on this element
 165       *
 166       * @param     string    $event  Name of event
 167       * @param     mixed     $arg    event arguments
 168       * @param     object    $caller calling object
 169       * @since     1.0
 170       * @access    public
 171       * @return    void
 172       * @throws    
 173       */
 174      function onQuickFormEvent($event, $arg, &$caller)
 175      {
 176          // do not use submit values for button-type elements
 177          $type = $this->getType();
 178          if (('updateValue' != $event) ||
 179              ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
 180              parent::onQuickFormEvent($event, $arg, $caller);
 181          } else {
 182              $value = $this->_findValue($caller->_constantValues);
 183              if (null === $value) {
 184                  $value = $this->_findValue($caller->_defaultValues);
 185              }
 186              if (null !== $value) {
 187                  $this->setValue($value);
 188              }
 189          }
 190          return true;
 191      } // end func onQuickFormEvent
 192  
 193      // }}}
 194      // {{{ exportValue()
 195  
 196     /**
 197      * We don't need values from button-type elements (except submit) and files
 198      */
 199      function exportValue(&$submitValues, $assoc = false)
 200      {
 201          $type = $this->getType();
 202          if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
 203              return null;
 204          } else {
 205              return parent::exportValue($submitValues, $assoc);
 206          }
 207      }
 208      
 209      // }}}
 210  } // end class HTML_QuickForm_element
 211  ?>