1<?php 2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4/** 5 * HTML class for a textarea type field 6 * 7 * PHP versions 4 and 5 8 * 9 * LICENSE: This source file is subject to version 3.01 of the PHP license 10 * that is available through the world-wide-web at the following URI: 11 * http://www.php.net/license/3_01.txt If you did not receive a copy of 12 * the PHP License and are unable to obtain it through the web, please 13 * send a note to license@php.net so we can mail you a copy immediately. 14 * 15 * @category HTML 16 * @package HTML_QuickForm 17 * @author Adam Daniel <adaniel1@eesus.jnj.com> 18 * @author Bertrand Mansion <bmansion@mamasam.com> 19 * @copyright 2001-2011 The PHP Group 20 * @license http://www.php.net/license/3_01.txt PHP License 3.01 21 * @version CVS: $Id$ 22 * @link http://pear.php.net/package/HTML_QuickForm 23 */ 24 25/** 26 * Base class for form elements 27 */ 28require_once 'HTML/QuickForm/element.php'; 29 30/** 31 * HTML class for a textarea type field 32 * 33 * @category HTML 34 * @package HTML_QuickForm 35 * @author Adam Daniel <adaniel1@eesus.jnj.com> 36 * @author Bertrand Mansion <bmansion@mamasam.com> 37 * @version Release: 3.2.16 38 * @since 1.0 39 */ 40class HTML_QuickForm_textarea extends HTML_QuickForm_element 41{ 42 // {{{ properties 43 44 /** 45 * Field value 46 * @var string 47 * @since 1.0 48 * @access private 49 */ 50 var $_value = null; 51 52 // }}} 53 // {{{ constructor 54 55 /** 56 * Class constructor 57 * 58 * @param string Input field name attribute 59 * @param mixed Label(s) for a field 60 * @param mixed Either a typical HTML attribute string or an associative array 61 * @since 1.0 62 * @access public 63 * @return void 64 */ 65 function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null) 66 { 67 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); 68 $this->_persistantFreeze = true; 69 $this->_type = 'textarea'; 70 } //end constructor 71 72 // }}} 73 // {{{ setName() 74 75 /** 76 * Sets the input field name 77 * 78 * @param string $name Input field name attribute 79 * @since 1.0 80 * @access public 81 * @return void 82 */ 83 function setName($name) 84 { 85 $this->updateAttributes(array('name'=>$name)); 86 } //end func setName 87 88 // }}} 89 // {{{ getName() 90 91 /** 92 * Returns the element name 93 * 94 * @since 1.0 95 * @access public 96 * @return string 97 */ 98 function getName() 99 { 100 return $this->getAttribute('name'); 101 } //end func getName 102 103 // }}} 104 // {{{ setValue() 105 106 /** 107 * Sets value for textarea element 108 * 109 * @param string $value Value for textarea element 110 * @since 1.0 111 * @access public 112 * @return void 113 */ 114 function setValue($value) 115 { 116 $this->_value = $value; 117 } //end func setValue 118 119 // }}} 120 // {{{ getValue() 121 122 /** 123 * Returns the value of the form element 124 * 125 * @since 1.0 126 * @access public 127 * @return string 128 */ 129 function getValue() 130 { 131 return $this->_value; 132 } // end func getValue 133 134 // }}} 135 // {{{ setWrap() 136 137 /** 138 * Sets wrap type for textarea element 139 * 140 * @param string $wrap Wrap type 141 * @since 1.0 142 * @access public 143 * @return void 144 */ 145 function setWrap($wrap) 146 { 147 $this->updateAttributes(array('wrap' => $wrap)); 148 } //end func setWrap 149 150 // }}} 151 // {{{ setRows() 152 153 /** 154 * Sets height in rows for textarea element 155 * 156 * @param string $rows Height expressed in rows 157 * @since 1.0 158 * @access public 159 * @return void 160 */ 161 function setRows($rows) 162 { 163 $this->updateAttributes(array('rows' => $rows)); 164 } //end func setRows 165 166 // }}} 167 // {{{ setCols() 168 169 /** 170 * Sets width in cols for textarea element 171 * 172 * @param string $cols Width expressed in cols 173 * @since 1.0 174 * @access public 175 * @return void 176 */ 177 function setCols($cols) 178 { 179 $this->updateAttributes(array('cols' => $cols)); 180 } //end func setCols 181 182 // }}} 183 // {{{ toHtml() 184 185 /** 186 * Returns the textarea element in HTML 187 * 188 * @since 1.0 189 * @access public 190 * @return string 191 */ 192 function toHtml() 193 { 194 if ($this->_flagFrozen) { 195 return $this->getFrozenHtml(); 196 } else { 197 return $this->_getTabs() . 198 '<textarea' . $this->_getAttrString($this->_attributes) . '>' . 199 // because we wrap the form later we don't want the text indented 200 preg_replace("/(\r\n|\n|\r)/", '
', htmlspecialchars($this->_value)) . 201 '</textarea>'; 202 } 203 } //end func toHtml 204 205 // }}} 206 // {{{ getFrozenHtml() 207 208 /** 209 * Returns the value of field without HTML tags (in this case, value is changed to a mask) 210 * 211 * @since 1.0 212 * @access public 213 * @return string 214 */ 215 function getFrozenHtml() 216 { 217 $value = htmlspecialchars($this->getValue()); 218 if ($this->getAttribute('wrap') == 'off') { 219 $html = $this->_getTabs() . '<pre>' . $value."</pre>\n"; 220 } else { 221 $html = nl2br($value)."\n"; 222 } 223 return $html . $this->_getPersistantData(); 224 } //end func getFrozenHtml 225 226 // }}} 227 228} //end class HTML_QuickForm_textarea 229?> 230