PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/pear/HTML/QuickForm/input.php

http://github.com/moodle/moodle
PHP | 211 lines | 68 code | 21 blank | 122 comment | 23 complexity | 8c61c4fbc34aaed022ea6f8ddb60f39a MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. require_once("HTML/QuickForm/element.php");
  22. /**
  23. * Base class for input form elements
  24. *
  25. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  26. * @author Bertrand Mansion <bmansion@mamasam.com>
  27. * @version 1.0
  28. * @since PHP4.04pl1
  29. * @access public
  30. * @abstract
  31. */
  32. class HTML_QuickForm_input extends HTML_QuickForm_element
  33. {
  34. // {{{ constructor
  35. /**
  36. * Class constructor
  37. *
  38. * @param string Input field name attribute
  39. * @param mixed Label(s) for the input field
  40. * @param mixed Either a typical HTML attribute string or an associative array
  41. * @since 1.0
  42. * @access public
  43. * @return void
  44. */
  45. public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
  46. parent::__construct($elementName, $elementLabel, $attributes);
  47. } //end constructor
  48. /**
  49. * Old syntax of class constructor. Deprecated in PHP7.
  50. *
  51. * @deprecated since Moodle 3.1
  52. */
  53. public function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null) {
  54. debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  55. self::__construct($elementName, $elementLabel, $attributes);
  56. }
  57. // }}}
  58. // {{{ setType()
  59. /**
  60. * Sets the element type
  61. *
  62. * @param string $type Element type
  63. * @since 1.0
  64. * @access public
  65. * @return void
  66. */
  67. function setType($type)
  68. {
  69. $this->_type = $type;
  70. $this->updateAttributes(array('type'=>$type));
  71. } // end func setType
  72. // }}}
  73. // {{{ setName()
  74. /**
  75. * Sets the input field name
  76. *
  77. * @param string $name Input field name attribute
  78. * @since 1.0
  79. * @access public
  80. * @return void
  81. */
  82. function setName($name)
  83. {
  84. $this->updateAttributes(array('name'=>$name));
  85. } //end func setName
  86. // }}}
  87. // {{{ getName()
  88. /**
  89. * Returns the element name
  90. *
  91. * @since 1.0
  92. * @access public
  93. * @return string
  94. */
  95. function getName()
  96. {
  97. return $this->getAttribute('name');
  98. } //end func getName
  99. // }}}
  100. // {{{ setValue()
  101. /**
  102. * Sets the value of the form element
  103. *
  104. * @param string $value Default value of the form element
  105. * @since 1.0
  106. * @access public
  107. * @return void
  108. */
  109. function setValue($value)
  110. {
  111. $this->updateAttributes(array('value'=>$value));
  112. } // end func setValue
  113. // }}}
  114. // {{{ getValue()
  115. /**
  116. * Returns the value of the form element
  117. *
  118. * @since 1.0
  119. * @access public
  120. * @return string
  121. */
  122. function getValue()
  123. {
  124. return $this->getAttribute('value');
  125. } // end func getValue
  126. // }}}
  127. // {{{ toHtml()
  128. /**
  129. * Returns the input field in HTML
  130. *
  131. * @since 1.0
  132. * @access public
  133. * @return string
  134. */
  135. function toHtml()
  136. {
  137. if ($this->_flagFrozen) {
  138. return $this->getFrozenHtml();
  139. } else {
  140. return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
  141. }
  142. } //end func toHtml
  143. // }}}
  144. // {{{ onQuickFormEvent()
  145. /**
  146. * Called by HTML_QuickForm whenever form event is made on this element
  147. *
  148. * @param string $event Name of event
  149. * @param mixed $arg event arguments
  150. * @param object $caller calling object
  151. * @since 1.0
  152. * @access public
  153. * @return void
  154. * @throws
  155. */
  156. function onQuickFormEvent($event, $arg, &$caller)
  157. {
  158. // do not use submit values for button-type elements
  159. $type = $this->getType();
  160. if (('updateValue' != $event) ||
  161. ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
  162. parent::onQuickFormEvent($event, $arg, $caller);
  163. } else {
  164. $value = $this->_findValue($caller->_constantValues);
  165. if (null === $value) {
  166. $value = $this->_findValue($caller->_defaultValues);
  167. }
  168. if (null !== $value) {
  169. $this->setValue($value);
  170. }
  171. }
  172. return true;
  173. } // end func onQuickFormEvent
  174. // }}}
  175. // {{{ exportValue()
  176. /**
  177. * We don't need values from button-type elements (except submit) and files
  178. */
  179. function exportValue(&$submitValues, $assoc = false)
  180. {
  181. $type = $this->getType();
  182. if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
  183. return null;
  184. } else {
  185. return parent::exportValue($submitValues, $assoc);
  186. }
  187. }
  188. // }}}
  189. } // end class HTML_QuickForm_element
  190. ?>