1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xoops\Form;
13:
14: /**
15: * TextArea - a text area element
16: *
17: * @category Xoops\Form\TextArea
18: * @package Xoops\Form
19: * @author Kazumi Ono <onokazu@xoops.org>
20: * @copyright 2001-2015 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class TextArea extends Element
25: {
26: /**
27: * Constructor
28: *
29: * @param string|array $caption Caption or array of all attributes
30: * @param string $name name
31: * @param string $value initial content
32: * @param integer $rows number of rows
33: * @param integer $cols number of columns
34: * @param string $placeholder placeholder for this element.
35: */
36: public function __construct($caption, $name = null, $value = "", $rows = 5, $cols = 50, $placeholder = '')
37: {
38: if (is_array($caption)) {
39: parent::__construct($caption);
40: $this->setIfNotSet('rows', 5);
41: $this->setIfNotSet('cols', 50);
42: } else {
43: parent::__construct([]);
44: $this->setWithDefaults('caption', $caption, '');
45: $this->setWithDefaults('name', $name, 'name_error');
46: $this->setWithDefaults('rows', $rows, 5);
47: $this->setWithDefaults('cols', $cols, 50);
48: $this->setWithDefaults('value', $value, '');
49: $this->setIfNotEmpty('placeholder', $placeholder);
50: }
51: }
52:
53: /**
54: * get number of rows
55: *
56: * @return int
57: */
58: public function getRows()
59: {
60: return (int) $this->get('rows');
61: }
62:
63: /**
64: * Get number of columns
65: *
66: * @return int
67: */
68: public function getCols()
69: {
70: return (int) $this->get('cols');
71: }
72:
73: /**
74: * Get placeholder for this element
75: *
76: * @return string
77: */
78: public function getPlaceholder()
79: {
80: return (string) $this->get('placeholder');
81: }
82:
83: /**
84: * prepare HTML for output
85: *
86: * @return string HTML
87: */
88: public function render()
89: {
90: $this->suppressRender(['value']);
91:
92: $this->themeDecorateElement();
93:
94: $attributes = $this->renderAttributeString();
95: return '<textarea ' . $attributes . ' ' . $this->getExtra() .' >'
96: . $this->getValue() . '</textarea>';
97: }
98: }
99: