static.php 4.4 KB

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