input.php 4.7 KB

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