adding some strings
[moodle-linuxchix.git] / lib / pear / HTML / QuickForm / textarea.php
blob7aa0af2ad6c1b72e37e6a4497bcbb664bd9c3cac
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 // +----------------------------------------------------------------------+
20 // $Id$
22 require_once("HTML/QuickForm/element.php");
24 /**
25 * HTML class for a textarea type field
27 * @author Adam Daniel <adaniel1@eesus.jnj.com>
28 * @author Bertrand Mansion <bmansion@mamasam.com>
29 * @version 1.0
30 * @since PHP4.04pl1
31 * @access public
33 class HTML_QuickForm_textarea extends HTML_QuickForm_element
35 // {{{ properties
37 /**
38 * Field value
39 * @var string
40 * @since 1.0
41 * @access private
43 var $_value = null;
45 // }}}
46 // {{{ constructor
48 /**
49 * Class constructor
51 * @param string Input field name attribute
52 * @param mixed Label(s) for a field
53 * @param mixed Either a typical HTML attribute string or an associative array
54 * @since 1.0
55 * @access public
56 * @return void
58 function HTML_QuickForm_textarea($elementName=null, $elementLabel=null, $attributes=null)
60 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
61 $this->_persistantFreeze = true;
62 $this->_type = 'textarea';
63 } //end constructor
65 // }}}
66 // {{{ setName()
68 /**
69 * Sets the input field name
71 * @param string $name Input field name attribute
72 * @since 1.0
73 * @access public
74 * @return void
76 function setName($name)
78 $this->updateAttributes(array('name'=>$name));
79 } //end func setName
81 // }}}
82 // {{{ getName()
84 /**
85 * Returns the element name
87 * @since 1.0
88 * @access public
89 * @return string
91 function getName()
93 return $this->getAttribute('name');
94 } //end func getName
96 // }}}
97 // {{{ setValue()
99 /**
100 * Sets value for textarea element
102 * @param string $value Value for textarea element
103 * @since 1.0
104 * @access public
105 * @return void
107 function setValue($value)
109 $this->_value = $value;
110 } //end func setValue
112 // }}}
113 // {{{ getValue()
116 * Returns the value of the form element
118 * @since 1.0
119 * @access public
120 * @return string
122 function getValue()
124 return $this->_value;
125 } // end func getValue
127 // }}}
128 // {{{ setWrap()
131 * Sets wrap type for textarea element
133 * @param string $wrap Wrap type
134 * @since 1.0
135 * @access public
136 * @return void
138 function setWrap($wrap)
140 $this->updateAttributes(array('wrap' => $wrap));
141 } //end func setWrap
143 // }}}
144 // {{{ setRows()
147 * Sets height in rows for textarea element
149 * @param string $rows Height expressed in rows
150 * @since 1.0
151 * @access public
152 * @return void
154 function setRows($rows)
156 $this->updateAttributes(array('rows' => $rows));
157 } //end func setRows
159 // }}}
160 // {{{ setCols()
163 * Sets width in cols for textarea element
165 * @param string $cols Width expressed in cols
166 * @since 1.0
167 * @access public
168 * @return void
170 function setCols($cols)
172 $this->updateAttributes(array('cols' => $cols));
173 } //end func setCols
175 // }}}
176 // {{{ toHtml()
179 * Returns the textarea element in HTML
181 * @since 1.0
182 * @access public
183 * @return string
185 function toHtml()
187 if ($this->_flagFrozen) {
188 return $this->getFrozenHtml();
189 } else {
190 return $this->_getTabs() .
191 '<textarea' . $this->_getAttrString($this->_attributes) . '>' .
192 // because we wrap the form later we don't want the text indented
193 preg_replace("/(\r\n|\n|\r)/", '&#010;', htmlspecialchars($this->_value)) .
194 '</textarea>';
196 } //end func toHtml
198 // }}}
199 // {{{ getFrozenHtml()
202 * Returns the value of field without HTML tags (in this case, value is changed to a mask)
204 * @since 1.0
205 * @access public
206 * @return string
208 function getFrozenHtml()
210 $value = htmlspecialchars($this->getValue());
211 if ($this->getAttribute('wrap') == 'off') {
212 $html = $this->_getTabs() . '<pre>' . $value."</pre>\n";
213 } else {
214 $html = nl2br($value)."\n";
216 return $html . $this->_getPersistantData();
217 } //end func getFrozenHtml
219 // }}}
221 } //end class HTML_QuickForm_textarea