static.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 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: static.php 6184 2005-09-07 10:08:17Z bmol $
  21. require_once("HTML/QuickForm/element.php");
  22. /**
  23. * HTML class for static data
  24. *
  25. * @author Wojciech Gdela <eltehaem@poczta.onet.pl>
  26. * @access public
  27. */
  28. class HTML_QuickForm_static extends HTML_QuickForm_element {
  29. // {{{ properties
  30. /**
  31. * Display text
  32. * @var string
  33. * @access private
  34. */
  35. var $_text = null;
  36. // }}}
  37. // {{{ constructor
  38. /**
  39. * Class constructor
  40. *
  41. * @param string $elementLabel (optional)Label
  42. * @param string $text (optional)Display text
  43. * @access public
  44. * @return void
  45. */
  46. function HTML_QuickForm_static($elementName=null, $elementLabel=null, $text=null)
  47. {
  48. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel);
  49. $this->_persistantFreeze = false;
  50. $this->_type = 'static';
  51. $this->_text = $text;
  52. } //end constructor
  53. // }}}
  54. // {{{ setName()
  55. /**
  56. * Sets the element name
  57. *
  58. * @param string $name Element name
  59. * @access public
  60. * @return void
  61. */
  62. function setName($name)
  63. {
  64. $this->updateAttributes(array('name'=>$name));
  65. } //end func setName
  66. // }}}
  67. // {{{ getName()
  68. /**
  69. * Returns the element name
  70. *
  71. * @access public
  72. * @return string
  73. */
  74. function getName()
  75. {
  76. return $this->getAttribute('name');
  77. } //end func getName
  78. // }}}
  79. // {{{ setText()
  80. /**
  81. * Sets the text
  82. *
  83. * @param string $text
  84. * @access public
  85. * @return void
  86. */
  87. function setText($text)
  88. {
  89. $this->_text = $text;
  90. } // end func setText
  91. // }}}
  92. // {{{ setValue()
  93. /**
  94. * Sets the text (uses the standard setValue call to emulate a form element.
  95. *
  96. * @param string $text
  97. * @access public
  98. * @return void
  99. */
  100. function setValue($text)
  101. {
  102. $this->setText($text);
  103. } // end func setValue
  104. // }}}
  105. // {{{ toHtml()
  106. /**
  107. * Returns the static text element in HTML
  108. *
  109. * @access public
  110. * @return string
  111. */
  112. function toHtml()
  113. {
  114. return $this->_getTabs() . $this->_text;
  115. } //end func toHtml
  116. // }}}
  117. // {{{ getFrozenHtml()
  118. /**
  119. * Returns the value of field without HTML tags
  120. *
  121. * @access public
  122. * @return string
  123. */
  124. function getFrozenHtml()
  125. {
  126. return $this->toHtml();
  127. } //end func getFrozenHtml
  128. // }}}
  129. // {{{ onQuickFormEvent()
  130. /**
  131. * Called by HTML_QuickForm whenever form event is made on this element
  132. *
  133. * @param string $event Name of event
  134. * @param mixed $arg event arguments
  135. * @param object $caller calling object
  136. * @since 1.0
  137. * @access public
  138. * @return void
  139. * @throws
  140. */
  141. function onQuickFormEvent($event, $arg, &$caller)
  142. {
  143. switch ($event) {
  144. case 'updateValue':
  145. // do NOT use submitted values for static elements
  146. $value = $this->_findValue($caller->_constantValues);
  147. if (null === $value) {
  148. $value = $this->_findValue($caller->_defaultValues);
  149. }
  150. if (null !== $value) {
  151. $this->setValue($value);
  152. }
  153. break;
  154. default:
  155. parent::onQuickFormEvent($event, $arg, $caller);
  156. }
  157. return true;
  158. } // end func onQuickFormEvent
  159. // }}}
  160. // {{{ exportValue()
  161. /**
  162. * We override this here because we don't want any values from static elements
  163. */
  164. function exportValue(&$submitValues, $assoc = false)
  165. {
  166. return null;
  167. }
  168. // }}}
  169. } //end class HTML_QuickForm_static
  170. ?>