style_button.php 5.9 KB

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