1: | <?php |
2: | /** |
3: | * XOOPS form element |
4: | * |
5: | * You may not change or alter any portion of this comment or credits |
6: | * of supporting developers from this source code or any supporting source code |
7: | * which is considered copyrighted (c) material of the original comment or credit authors. |
8: | * This program is distributed in the hope that it will be useful, |
9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11: | * |
12: | * @copyright (c) 2000-2017 XOOPS Project (www.xoops.org) |
13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14: | * @package kernel |
15: | * @subpackage form |
16: | * @since 2.0.0 |
17: | * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
18: | */ |
19: | |
20: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
21: | |
22: | /** |
23: | * A simple text field |
24: | */ |
25: | class XoopsFormText extends XoopsFormElement |
26: | { |
27: | /** |
28: | * Size |
29: | * |
30: | * @var int |
31: | * @access private |
32: | */ |
33: | public $_size; |
34: | |
35: | /** |
36: | * Maximum length of the text |
37: | * |
38: | * @var int |
39: | * @access private |
40: | */ |
41: | public $_maxlength; |
42: | |
43: | /** |
44: | * Initial text |
45: | * |
46: | * @var string |
47: | * @access private |
48: | */ |
49: | public $_value; |
50: | |
51: | /** |
52: | * Constructor |
53: | * |
54: | * @param string $caption Caption |
55: | * @param string $name "name" attribute |
56: | * @param int $size Size |
57: | * @param int $maxlength Maximum length of text |
58: | * @param string $value Initial text |
59: | */ |
60: | public function __construct($caption, $name, $size, $maxlength, $value = '') |
61: | { |
62: | $this->setCaption($caption); |
63: | $this->setName($name); |
64: | $this->_size = (int)$size; |
65: | $this->_maxlength = (int)$maxlength; |
66: | $this->setValue($value); |
67: | } |
68: | |
69: | /** |
70: | * Get size |
71: | * |
72: | * @return int |
73: | */ |
74: | public function getSize() |
75: | { |
76: | return $this->_size; |
77: | } |
78: | |
79: | /** |
80: | * Get maximum text length |
81: | * |
82: | * @return int |
83: | */ |
84: | public function getMaxlength() |
85: | { |
86: | return $this->_maxlength; |
87: | } |
88: | |
89: | /** |
90: | * Get initial content |
91: | * |
92: | * @param bool $encode To sanitizer the text? Default value should be "true"; however we have to set "false" for backward compatibility |
93: | * @return string |
94: | */ |
95: | public function getValue($encode = false) |
96: | { |
97: | return $encode ? htmlspecialchars($this->_value, ENT_QUOTES) : $this->_value; |
98: | } |
99: | |
100: | /** |
101: | * Set initial text value |
102: | * |
103: | * @param string $value |
104: | */ |
105: | public function setValue($value) |
106: | { |
107: | $this->_value = $value; |
108: | } |
109: | |
110: | /** |
111: | * Prepare HTML for output |
112: | * |
113: | * @return string HTML |
114: | */ |
115: | public function render() |
116: | { |
117: | return XoopsFormRenderer::getInstance()->get()->renderFormText($this); |
118: | } |
119: | } |
120: |