PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/include/HTML/QuickForm/input.php

https://github.com/radicaldesigns/amp
PHP | 202 lines | 65 code | 20 blank | 117 comment | 23 complexity | 38b57781cb7401e49ceb61057b63a85f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
  17. // | Bertrand Mansion <bmansion@mamasam.com> |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: input.php,v 1.8 2003/06/18 19:36:20 avb Exp $
  21. require_once("HTML/QuickForm/element.php");
  22. /**
  23. * Base class for input form elements
  24. *
  25. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  26. * @author Bertrand Mansion <bmansion@mamasam.com>
  27. * @version 1.0
  28. * @since PHP4.04pl1
  29. * @access public
  30. * @abstract
  31. */
  32. class HTML_QuickForm_input extends HTML_QuickForm_element
  33. {
  34. // {{{ constructor
  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. function HTML_QuickForm_input($elementName=null, $elementLabel=null, $attributes=null)
  46. {
  47. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  48. } //end constructor
  49. // }}}
  50. // {{{ setType()
  51. /**
  52. * Sets the element type
  53. *
  54. * @param string $type Element type
  55. * @since 1.0
  56. * @access public
  57. * @return void
  58. */
  59. function setType($type)
  60. {
  61. $this->_type = $type;
  62. $this->updateAttributes(array('type'=>$type));
  63. } // end func setType
  64. // }}}
  65. // {{{ setName()
  66. /**
  67. * Sets the input field name
  68. *
  69. * @param string $name Input field name attribute
  70. * @since 1.0
  71. * @access public
  72. * @return void
  73. */
  74. function setName($name)
  75. {
  76. $this->updateAttributes(array('name'=>$name));
  77. } //end func setName
  78. // }}}
  79. // {{{ getName()
  80. /**
  81. * Returns the element name
  82. *
  83. * @since 1.0
  84. * @access public
  85. * @return string
  86. */
  87. function getName()
  88. {
  89. return $this->getAttribute('name');
  90. } //end func getName
  91. // }}}
  92. // {{{ setValue()
  93. /**
  94. * Sets the value of the form element
  95. *
  96. * @param string $value Default value of the form element
  97. * @since 1.0
  98. * @access public
  99. * @return void
  100. */
  101. function setValue($value)
  102. {
  103. $this->updateAttributes(array('value'=>$value));
  104. } // end func setValue
  105. // }}}
  106. // {{{ getValue()
  107. /**
  108. * Returns the value of the form element
  109. *
  110. * @since 1.0
  111. * @access public
  112. * @return string
  113. */
  114. function getValue()
  115. {
  116. return $this->getAttribute('value');
  117. } // end func getValue
  118. // }}}
  119. // {{{ toHtml()
  120. /**
  121. * Returns the input field in HTML
  122. *
  123. * @since 1.0
  124. * @access public
  125. * @return string
  126. */
  127. function toHtml()
  128. {
  129. if ($this->_flagFrozen) {
  130. return $this->getFrozenHtml();
  131. } else {
  132. return $this->_getTabs() . '<input' . $this->_getAttrString($this->_attributes) . ' />';
  133. }
  134. } //end func toHtml
  135. // }}}
  136. // {{{ onQuickFormEvent()
  137. /**
  138. * Called by HTML_QuickForm whenever form event is made on this element
  139. *
  140. * @param string $event Name of event
  141. * @param mixed $arg event arguments
  142. * @param object $caller calling object
  143. * @since 1.0
  144. * @access public
  145. * @return void
  146. * @throws
  147. */
  148. function onQuickFormEvent($event, $arg, &$caller)
  149. {
  150. // do not use submit values for button-type elements
  151. $type = $this->getType();
  152. if (('updateValue' != $event) ||
  153. ('submit' != $type && 'reset' != $type && 'image' != $type && 'button' != $type)) {
  154. parent::onQuickFormEvent($event, $arg, $caller);
  155. } else {
  156. $value = $this->_findValue($caller->_constantValues);
  157. if (null === $value) {
  158. $value = $this->_findValue($caller->_defaultValues);
  159. }
  160. if (null !== $value) {
  161. $this->setValue($value);
  162. }
  163. }
  164. return true;
  165. } // end func onQuickFormEvent
  166. // }}}
  167. // {{{ exportValue()
  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. // }}}
  181. } // end class HTML_QuickForm_element
  182. ?>