PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/campsite/src/include/pear/HTML/QuickForm/input.php

https://github.com/joechrysler/Campsite
PHP | 209 lines | 65 code | 21 blank | 123 comment | 23 complexity | cf33b90613fa447e8b784f70e84eafba MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Base class for <input /> form elements
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  17. * @author Bertrand Mansion <bmansion@mamasam.com>
  18. * @copyright 2001-2009 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: input.php,v 1.10 2009/04/04 21:34:03 avb Exp $
  21. * @link http://pear.php.net/package/HTML_QuickForm
  22. */
  23. /**
  24. * Base class for form elements
  25. */
  26. require_once 'HTML/QuickForm/element.php';
  27. /**
  28. * Base class for <input /> form elements
  29. *
  30. * @category HTML
  31. * @package HTML_QuickForm
  32. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  33. * @author Bertrand Mansion <bmansion@mamasam.com>
  34. * @version Release: 3.2.11
  35. * @since 1.0
  36. * @abstract
  37. */
  38. class HTML_QuickForm_input extends HTML_QuickForm_element
  39. {
  40. // {{{ constructor
  41. /**
  42. * Class constructor
  43. *
  44. * @param string Input field name attribute
  45. * @param mixed Label(s) for the input field
  46. * @param mixed Either a typical HTML attribute string or an associative array
  47. * @since 1.0
  48. * @access public
  49. * @return void
  50. */
  51. function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null)
  52. {
  53. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  54. } //end constructor
  55. // }}}
  56. // {{{ setType()
  57. /**
  58. * Sets the element type
  59. *
  60. * @param string $type Element type
  61. * @since 1.0
  62. * @access public
  63. * @return void
  64. */
  65. function setType($type)
  66. {
  67. $this->_type = $type;
  68. $this->updateAttributes(array('type'=>$type));
  69. } // end func setType
  70. // }}}
  71. // {{{ setName()
  72. /**
  73. * Sets the input field name
  74. *
  75. * @param string $name Input field name attribute
  76. * @since 1.0
  77. * @access public
  78. * @return void
  79. */
  80. function setName($name)
  81. {
  82. $this->updateAttributes(array('name'=>$name));
  83. } //end func setName
  84. // }}}
  85. // {{{ getName()
  86. /**
  87. * Returns the element name
  88. *
  89. * @since 1.0
  90. * @access public
  91. * @return string
  92. */
  93. function getName()
  94. {
  95. return $this->getAttribute('name');
  96. } //end func getName
  97. // }}}
  98. // {{{ setValue()
  99. /**
  100. * Sets the value of the form element
  101. *
  102. * @param string $value Default value of the form element
  103. * @since 1.0
  104. * @access public
  105. * @return void
  106. */
  107. function setValue($value)
  108. {
  109. $this->updateAttributes(array('value'=>$value));
  110. } // end func setValue
  111. // }}}
  112. // {{{ getValue()
  113. /**
  114. * Returns the value of the form element
  115. *
  116. * @since 1.0
  117. * @access public
  118. * @return string
  119. */
  120. function getValue()
  121. {
  122. return $this->getAttribute('value');
  123. } // end func getValue
  124. // }}}
  125. // {{{ toHtml()
  126. /**
  127. * Returns the input field in HTML
  128. *
  129. * @since 1.0
  130. * @access public
  131. * @return string
  132. */
  133. function toHtml()
  134. {
  135. if ($this->_flagFrozen) {
  136. return $this->getFrozenHtml();
  137. } else {
  138. return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
  139. }
  140. } //end func toHtml
  141. // }}}
  142. // {{{ onQuickFormEvent()
  143. /**
  144. * Called by HTML_QuickForm whenever form event is made on this element
  145. *
  146. * @param string $event Name of event
  147. * @param mixed $arg event arguments
  148. * @param object &$caller calling object
  149. * @since 1.0
  150. * @access public
  151. * @return void
  152. * @throws
  153. */
  154. function onQuickFormEvent($event, $arg, &$caller)
  155. {
  156. // do not use submit values for button-type elements
  157. $type = $this->getType();
  158. if (('updateValue' != $event) ||
  159. ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
  160. parent::onQuickFormEvent($event, $arg, $caller);
  161. } else {
  162. $value = $this->_findValue($caller->_constantValues);
  163. if (null === $value) {
  164. $value = $this->_findValue($caller->_defaultValues);
  165. }
  166. if (null !== $value) {
  167. $this->setValue($value);
  168. }
  169. }
  170. return true;
  171. } // end func onQuickFormEvent
  172. // }}}
  173. // {{{ exportValue()
  174. /**
  175. * We don't need values from button-type elements (except submit) and files
  176. */
  177. function exportValue(&$submitValues, $assoc = false)
  178. {
  179. $type = $this->getType();
  180. if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
  181. return null;
  182. } else {
  183. return parent::exportValue($submitValues, $assoc);
  184. }
  185. }
  186. // }}}
  187. } // end class HTML_QuickForm_element
  188. ?>