style_button.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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-2007 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: input.php 17344 2008-12-17 08:55:29Z Scara84 $
  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 <button></button> form elements
  29. *
  30. * @category HTML
  31. * @package HTML_QuickForm
  32. * @author Hans De Bisschop <hans.de.bisschop@ehb.be>
  33. * @abstract
  34. */
  35. class HTML_QuickForm_stylebutton extends HTML_QuickForm_element
  36. {
  37. // {{{ properties
  38. /* Path to image */
  39. // {{{ constructor
  40. /**
  41. * Class constructor
  42. *
  43. * @param string Input field name attribute
  44. * @param mixed Label(s) for the input field
  45. * @param mixed Either a typical HTML attribute string or an associative array
  46. * @since 1.0
  47. * @access public
  48. * @return void
  49. */
  50. function HTML_QuickForm_stylebutton($elementName=null, $elementLabel=null, $attributes=null)
  51. {
  52. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  53. } //end constructor
  54. // }}}
  55. // {{{ setType()
  56. /**
  57. * Sets the element type
  58. *
  59. * @param string $type Element type
  60. * @since 1.0
  61. * @access public
  62. * @return void
  63. */
  64. /* Returns an HTML formatted attribute string
  65. * @param array $attributes
  66. * @return string
  67. * @access private
  68. */
  69. function _getAttrString($attributes)
  70. {
  71. $strAttr = '';
  72. if (is_array($attributes)) {
  73. foreach ($attributes as $key => $value) {
  74. if ($key != 'value') $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
  75. }
  76. }
  77. return $strAttr;
  78. } // end func _getAttrString
  79. function setType($type)
  80. {
  81. $this->_type = $type;
  82. $this->updateAttributes(array('type'=>$type));
  83. } // end func setType
  84. // }}}
  85. // {{{ setName()
  86. /**
  87. * Sets the input field name
  88. *
  89. * @param string $name Input field name attribute
  90. * @since 1.0
  91. * @access public
  92. * @return void
  93. */
  94. function setName($name)
  95. {
  96. $this->updateAttributes(array('name'=>$name));
  97. } //end func setName
  98. // }}}
  99. // {{{ getName()
  100. /**
  101. * Returns the element name
  102. *
  103. * @since 1.0
  104. * @access public
  105. * @return string
  106. */
  107. function getName()
  108. {
  109. return $this->getAttribute('name');
  110. } //end func getName
  111. // }}}
  112. // {{{ setValue()
  113. /**
  114. * Sets the value of the form element
  115. *
  116. * @param string $value Default value of the form element
  117. * @since 1.0
  118. * @access public
  119. * @return void
  120. */
  121. function setValue($value)
  122. {
  123. $this->updateAttributes(array('value'=>$value));
  124. } // end func setValue
  125. // }}}
  126. // {{{ getValue()
  127. /**
  128. * Returns the value of the form element
  129. *
  130. * @since 1.0
  131. * @access public
  132. * @return string
  133. */
  134. function getValue()
  135. {
  136. //return $this->getAttribute('value');
  137. return $this->_attributes['value'];
  138. } // end func getValue
  139. // }}}
  140. // {{{ toHtml()
  141. /**
  142. * Returns the input field in HTML
  143. *
  144. * @since 1.0
  145. * @access public
  146. * @return string
  147. */
  148. function toHtml()
  149. {
  150. if ($this->_flagFrozen) {
  151. return $this->getFrozenHtml();
  152. } else {
  153. return $this->_getTabs() . '<button' . $this->_getAttrString($this->_attributes) . ' >'.$this->getValue() .'</button>';
  154. }
  155. } //end func toHtml
  156. // }}}
  157. // {{{ onQuickFormEvent()
  158. /**
  159. * Called by HTML_QuickForm whenever form event is made on this element
  160. *
  161. * @param string $event Name of event
  162. * @param mixed $arg event arguments
  163. * @param object &$caller calling object
  164. * @since 1.0
  165. * @access public
  166. * @return void
  167. * @throws
  168. */
  169. function onQuickFormEvent($event, $arg, &$caller)
  170. {
  171. // do not use submit values for button-type elements
  172. $type = $this->getType();
  173. if (('updateValue' != $event) ||
  174. ('submit' != $type && 'reset' != $type && 'button' != $type)) {
  175. parent::onQuickFormEvent($event, $arg, $caller);
  176. } else {
  177. $value = $this->_findValue($caller->_constantValues);
  178. if (null === $value) {
  179. $value = $this->_findValue($caller->_defaultValues);
  180. }
  181. if (null !== $value) {
  182. $this->setValue($value);
  183. }
  184. }
  185. return true;
  186. } // end func onQuickFormEvent
  187. // }}}
  188. // {{{ exportValue()
  189. /**
  190. * We don't need values from button-type elements (except submit) and files
  191. */
  192. function exportValue(&$submitValues, $assoc = false)
  193. {
  194. $type = $this->getType();
  195. if ('reset' == $type || 'button' == $type) {
  196. return null;
  197. } else {
  198. return parent::exportValue($submitValues, $assoc);
  199. }
  200. }
  201. // }}}
  202. } // end class HTML_QuickForm_element
  203. ?>