|
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
|
|
|
* Text - a simple text field |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xoops\Form\Text |
|
18
|
|
|
* @package Xoops\Form |
|
19
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.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 Text extends Element |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* __construct |
|
28
|
|
|
* |
|
29
|
|
|
* @param string|array $caption Caption or array of all attributes |
|
30
|
|
|
* @param string $name name attribute |
|
31
|
|
|
* @param integer $size Size |
|
32
|
|
|
* @param integer $maxlength Maximum length of text |
|
33
|
|
|
* @param string $value Initial text |
|
34
|
|
|
* @param string $placeholder placeholder for this element. |
|
35
|
|
|
*/ |
|
36
|
20 |
|
public function __construct($caption, $name = null, $size = 10, $maxlength = 64, $value = '', $placeholder = '') |
|
37
|
|
|
{ |
|
38
|
20 |
|
if (is_array($caption)) { |
|
39
|
11 |
|
parent::__construct($caption); |
|
40
|
|
|
} else { |
|
41
|
9 |
|
parent::__construct([]); |
|
42
|
9 |
|
$this->setWithDefaults('caption', $caption, ''); |
|
43
|
9 |
|
$this->setWithDefaults('name', $name, 'name_error'); |
|
44
|
9 |
|
$this->setWithDefaults('size', $size, 10); |
|
45
|
9 |
|
$this->setWithDefaults('maxlength', $maxlength, 64); |
|
46
|
9 |
|
$this->set('value', $value); |
|
47
|
9 |
|
$this->setIfNotEmpty('placeholder', $placeholder); |
|
48
|
|
|
} |
|
49
|
20 |
|
$this->setIfNotSet('type', 'text'); |
|
50
|
20 |
|
$this->setIfNotSet('value', ''); |
|
51
|
20 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get size |
|
55
|
|
|
* |
|
56
|
|
|
* @return int |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getSize() |
|
59
|
|
|
{ |
|
60
|
1 |
|
return (int) $this->get('size'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get maximum text length |
|
65
|
|
|
* |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function getMaxlength() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return (int) $this->get('maxlength'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get placeholder for this element |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function getPlaceholder() |
|
79
|
|
|
{ |
|
80
|
1 |
|
return (string) $this->get('placeholder'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* defaultRender |
|
85
|
|
|
* |
|
86
|
|
|
* @return string rendered form element |
|
87
|
|
|
*/ |
|
88
|
5 |
|
public function defaultRender() |
|
89
|
|
|
{ |
|
90
|
5 |
|
$dataList = $this->isDatalist(); |
|
91
|
5 |
|
if (!empty($dataList)) { |
|
92
|
5 |
|
$this->add('list', 'list_' . $this->getName()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$attributes = $this->renderAttributeString(); |
|
96
|
5 |
|
return '<input ' . $attributes . ' ' . $this->getExtra() .' >'; |
|
97
|
5 |
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|