textarea.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 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: textarea.php 20456 2009-05-10 17:27:44Z ivantcholakov $
  21. require_once("HTML/QuickForm/element.php");
  22. /**
  23. * HTML class for a textarea type field
  24. *
  25. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  26. * @author Bertrand Mansion <bmansion@mamasam.com>
  27. * @version 1.0
  28. * @since PHP4.04pl1
  29. * @access public
  30. */
  31. class HTML_QuickForm_textarea extends HTML_QuickForm_element
  32. {
  33. // {{{ properties
  34. /**
  35. * Field value
  36. * @var string
  37. * @since 1.0
  38. * @access private
  39. */
  40. var $_value = null;
  41. // }}}
  42. // {{{ constructor
  43. /**
  44. * Class constructor
  45. *
  46. * @param string Input field name attribute
  47. * @param mixed Label(s) for a field
  48. * @param mixed Either a typical HTML attribute string or an associative array
  49. * @since 1.0
  50. * @access public
  51. * @return void
  52. */
  53. function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
  54. {
  55. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  56. $this->_persistantFreeze = true;
  57. $this->_type = 'textarea';
  58. } //end constructor
  59. // }}}
  60. // {{{ setName()
  61. /**
  62. * Sets the input field name
  63. *
  64. * @param string $name Input field name attribute
  65. * @since 1.0
  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. * @since 1.0
  79. * @access public
  80. * @return string
  81. */
  82. function getName()
  83. {
  84. return $this->getAttribute('name');
  85. } //end func getName
  86. // }}}
  87. // {{{ setValue()
  88. /**
  89. * Sets value for textarea element
  90. *
  91. * @param string $value Value for textarea element
  92. * @since 1.0
  93. * @access public
  94. * @return void
  95. */
  96. function setValue($value)
  97. {
  98. $this->_value = $value;
  99. } //end func setValue
  100. // }}}
  101. // {{{ getValue()
  102. /**
  103. * Returns the value of the form element
  104. *
  105. * @since 1.0
  106. * @access public
  107. * @return string
  108. */
  109. function getValue()
  110. {
  111. return $this->_value;
  112. } // end func getValue
  113. // }}}
  114. // {{{ setWrap()
  115. /**
  116. * Sets wrap type for textarea element
  117. *
  118. * @param string $wrap Wrap type
  119. * @since 1.0
  120. * @access public
  121. * @return void
  122. */
  123. function setWrap($wrap)
  124. {
  125. $this->updateAttributes(array('wrap' => $wrap));
  126. } //end func setWrap
  127. // }}}
  128. // {{{ setRows()
  129. /**
  130. * Sets height in rows for textarea element
  131. *
  132. * @param string $rows Height expressed in rows
  133. * @since 1.0
  134. * @access public
  135. * @return void
  136. */
  137. function setRows($rows)
  138. {
  139. $this->updateAttributes(array('rows' => $rows));
  140. } //end func setRows
  141. // }}}
  142. // {{{ setCols()
  143. /**
  144. * Sets width in cols for textarea element
  145. *
  146. * @param string $cols Width expressed in cols
  147. * @since 1.0
  148. * @access public
  149. * @return void
  150. */
  151. function setCols($cols)
  152. {
  153. $this->updateAttributes(array('cols' => $cols));
  154. } //end func setCols
  155. // }}}
  156. // {{{ toHtml()
  157. /**
  158. * Returns the textarea element in HTML
  159. *
  160. * @since 1.0
  161. * @access public
  162. * @return string
  163. */
  164. function toHtml()
  165. {
  166. if ($this->_flagFrozen) {
  167. return $this->getFrozenHtml();
  168. } else {
  169. global $charset;
  170. return $this->_getTabs() .
  171. '<textarea' . $this->_getAttrString($this->_attributes) . '>' .
  172. // because we wrap the form later we don't want the text indented
  173. preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value, ENT_COMPAT, $charset)) .
  174. '</textarea>';
  175. }
  176. } //end func toHtml
  177. // }}}
  178. // {{{ getFrozenHtml()
  179. /**
  180. * Returns the value of field without HTML tags (in this case, value is changed to a mask)
  181. *
  182. * @since 1.0
  183. * @access public
  184. * @return string
  185. */
  186. function getFrozenHtml()
  187. {
  188. global $charset;
  189. $value = htmlspecialchars($this->getValue(), ENT_COMPAT, $charset);
  190. if ($this->getAttribute('wrap') == 'off') {
  191. $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
  192. } else {
  193. $html = nl2br($value)."\n";
  194. }
  195. return $html . $this->_getPersistantData();
  196. } //end func getFrozenHtml
  197. // }}}
  198. } //end class HTML_QuickForm_textarea
  199. ?>