static.php 4.1 KB

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