input.php 5.2 KB

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