static.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * HTML class for static data
  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 Wojciech Gdela <eltehaem@poczta.onet.pl>
  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: static.php,v 1.8 2009/04/04 21:34:04 avb Exp $
  20. * @link http://pear.php.net/package/HTML_QuickForm
  21. */
  22. /**
  23. * Base class for form elements
  24. */
  25. require_once 'HTML/QuickForm/element.php';
  26. /**
  27. * HTML class for static data
  28. *
  29. * @category HTML
  30. * @package HTML_QuickForm
  31. * @author Wojciech Gdela <eltehaem@poczta.onet.pl>
  32. * @version Release: 3.2.11
  33. * @since 2.7
  34. */
  35. class HTML_QuickForm_static extends HTML_QuickForm_element {
  36. // {{{ properties
  37. /**
  38. * Display text
  39. * @var string
  40. * @access private
  41. */
  42. var $_text = null;
  43. // }}}
  44. // {{{ constructor
  45. /**
  46. * Class constructor
  47. *
  48. * @param string $elementLabel (optional)Label
  49. * @param string $text (optional)Display text
  50. * @access public
  51. * @return void
  52. */
  53. function HTML_QuickForm_static($elementName = null, $elementLabel = null, $text = null, $attributes = null)
  54. {
  55. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  56. $this->_persistantFreeze = false;
  57. $this->_type = 'static';
  58. $this->_text = $text;
  59. } //end constructor
  60. // }}}
  61. // {{{ setName()
  62. /**
  63. * Sets the element name
  64. *
  65. * @param string $name Element name
  66. * @access public
  67. * @return void
  68. */
  69. function setName($name)
  70. {
  71. $this->updateAttributes(array('name'=>$name));
  72. } //end func setName
  73. // }}}
  74. // {{{ getName()
  75. /**
  76. * Returns the element name
  77. *
  78. * @access public
  79. * @return string
  80. */
  81. function getName()
  82. {
  83. return $this->getAttribute('name');
  84. } //end func getName
  85. // }}}
  86. // {{{ setText()
  87. /**
  88. * Sets the text
  89. *
  90. * @param string $text
  91. * @access public
  92. * @return void
  93. */
  94. function setText($text)
  95. {
  96. $this->_text = $text;
  97. } // end func setText
  98. // }}}
  99. // {{{ setValue()
  100. /**
  101. * Sets the text (uses the standard setValue call to emulate a form element.
  102. *
  103. * @param string $text
  104. * @access public
  105. * @return void
  106. */
  107. function setValue($text)
  108. {
  109. $this->setText($text);
  110. } // end func setValue
  111. // }}}
  112. // {{{ toHtml()
  113. /**
  114. * Returns the static text element in HTML
  115. *
  116. * @access public
  117. * @return string
  118. */
  119. function toHtml()
  120. {
  121. return $this->_getTabs() . $this->_text;
  122. } //end func toHtml
  123. // }}}
  124. // {{{ getFrozenHtml()
  125. /**
  126. * Returns the value of field without HTML tags
  127. *
  128. * @access public
  129. * @return string
  130. */
  131. function getFrozenHtml()
  132. {
  133. return $this->toHtml();
  134. } //end func getFrozenHtml
  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. switch ($event) {
  151. case 'updateValue':
  152. // do NOT use submitted values for static elements
  153. $value = $this->_findValue($caller->_constantValues);
  154. if (null === $value) {
  155. $value = $this->_findValue($caller->_defaultValues);
  156. }
  157. if (null !== $value) {
  158. $this->setValue($value);
  159. }
  160. break;
  161. default:
  162. parent::onQuickFormEvent($event, $arg, $caller);
  163. }
  164. return true;
  165. } // end func onQuickFormEvent
  166. // }}}
  167. // {{{ exportValue()
  168. /**
  169. * We override this here because we don't want any values from static elements
  170. */
  171. function exportValue(&$submitValues, $assoc = false)
  172. {
  173. return null;
  174. }
  175. // }}}
  176. } //end class HTML_QuickForm_static
  177. ?>