input.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. * Sets the element type
  37. *
  38. * @param string $type Element type
  39. * @since 1.0
  40. * @access public
  41. * @return void
  42. */
  43. public function setType($type)
  44. {
  45. $this->_type = $type;
  46. $this->updateAttributes(array('type'=>$type));
  47. }
  48. /**
  49. * Sets the input field name
  50. *
  51. * @param string $name Input field name attribute
  52. * @since 1.0
  53. * @access public
  54. * @return void
  55. */
  56. public function setName($name)
  57. {
  58. $this->updateAttributes(array('name'=>$name));
  59. }
  60. /**
  61. * Returns the element name
  62. *
  63. * @since 1.0
  64. * @access public
  65. * @return string
  66. */
  67. public function getName()
  68. {
  69. return $this->getAttribute('name');
  70. }
  71. /**
  72. * Sets the value of the form element
  73. *
  74. * @param string $value Default value of the form element
  75. * @since 1.0
  76. * @access public
  77. * @return void
  78. */
  79. public function setValue($value)
  80. {
  81. $this->updateAttributes(array('value' => $value));
  82. }
  83. /**
  84. * Returns the value of the form element
  85. *
  86. * @since 1.0
  87. * @access public
  88. * @return string
  89. */
  90. public function getValue()
  91. {
  92. return $this->getAttribute('value');
  93. }
  94. /**
  95. * Returns the input field in HTML
  96. *
  97. * @since 1.0
  98. * @access public
  99. * @return string
  100. */
  101. public function toHtml()
  102. {
  103. if ($this->isFrozen()) {
  104. return $this->getFrozenHtml();
  105. } else {
  106. return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
  107. }
  108. }
  109. /**
  110. * Called by HTML_QuickForm whenever form event is made on this element
  111. *
  112. * @param string $event Name of event
  113. * @param mixed $arg event arguments
  114. * @param object &$caller calling object
  115. * @since 1.0
  116. * @access public
  117. * @return void
  118. * @throws
  119. */
  120. public function onQuickFormEvent($event, $arg, &$caller)
  121. {
  122. // do not use submit values for button-type elements
  123. $type = $this->getType();
  124. if (('updateValue' != $event) ||
  125. ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
  126. parent::onQuickFormEvent($event, $arg, $caller);
  127. } else {
  128. $value = $this->_findValue($caller->_constantValues);
  129. if (null === $value) {
  130. $value = $this->_findValue($caller->_defaultValues);
  131. }
  132. if (null !== $value) {
  133. $this->setValue($value);
  134. }
  135. }
  136. return true;
  137. }
  138. /**
  139. * We don't need values from button-type elements (except submit) and files
  140. */
  141. public function exportValue(&$submitValues, $assoc = false)
  142. {
  143. $type = $this->getType();
  144. if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
  145. return null;
  146. } else {
  147. return parent::exportValue($submitValues, $assoc);
  148. }
  149. }
  150. }