input.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. public $icon;
  41. // {{{ constructor
  42. /**
  43. * Class constructor
  44. *
  45. * @param string Input field name attribute
  46. * @param mixed Label(s) for the input field
  47. * @param mixed Either a typical HTML attribute string or an associative array
  48. * @since 1.0
  49. * @access public
  50. * @return void
  51. */
  52. function HTML_QuickForm_input($elementName = null, $elementLabel = null, $attributes = null)
  53. {
  54. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  55. if (isset($attributes) && is_array($attributes) && !empty($attributes['icon'])) {
  56. $this->icon = $attributes['icon'];
  57. }
  58. }
  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. }
  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. $html = null;
  139. if (!empty($this->icon)) {
  140. $html .= '<div class="input-group"><span class="input-group-addon"><i class="'.$this->icon.'"></i></span>';
  141. }
  142. $html .= $this->_getTabs().'<input' . $this->_getAttrString($this->_attributes).' />';
  143. if (!empty($this->icon)) {
  144. $html .= '</div>';
  145. }
  146. return $html;
  147. }
  148. } //end func toHtml
  149. // }}}
  150. // {{{ onQuickFormEvent()
  151. /**
  152. * Called by HTML_QuickForm whenever form event is made on this element
  153. *
  154. * @param string $event Name of event
  155. * @param mixed $arg event arguments
  156. * @param object &$caller calling object
  157. * @since 1.0
  158. * @access public
  159. * @return void
  160. * @throws
  161. */
  162. function onQuickFormEvent($event, $arg, &$caller)
  163. {
  164. // do not use submit values for button-type elements
  165. $type = $this->getType();
  166. if (('updateValue' != $event) ||
  167. ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
  168. parent::onQuickFormEvent($event, $arg, $caller);
  169. } else {
  170. $value = $this->_findValue($caller->_constantValues);
  171. if (null === $value) {
  172. $value = $this->_findValue($caller->_defaultValues);
  173. }
  174. if (null !== $value) {
  175. $this->setValue($value);
  176. }
  177. }
  178. return true;
  179. } // end func onQuickFormEvent
  180. // }}}
  181. // {{{ exportValue()
  182. /**
  183. * We don't need values from button-type elements (except submit) and files
  184. */
  185. function exportValue(&$submitValues, $assoc = false)
  186. {
  187. $type = $this->getType();
  188. if ('reset' == $type || 'image' == $type || 'button' == $type || 'file' == $type) {
  189. return null;
  190. } else {
  191. return parent::exportValue($submitValues, $assoc);
  192. }
  193. }
  194. // }}}
  195. } // end class HTML_QuickForm_element
  196. ?>