XOOPS  2.6.0
Text.php
Go to the documentation of this file.
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 
25 class Text extends Element
26 {
33  //private $size;
34 
42  //private $maxlength;
43 
50  //private $placeholder;
51 
62  public function __construct($caption, $name, $size, $maxlength, $value = '', $placeholder = '')
63  {
64  $this->setAttribute('type', 'text');
65  $this->setCaption($caption);
66  $this->setAttribute('name', $name);
67  $this->setAttribute('size', intval($size));
68  $this->setAttribute('maxlength', intval($maxlength));
69  $this->setValue($value);
70  if (!empty($placeholder)) {
71  $this->setAttribute('placeholder', $placeholder);
72  }
73  }
74 
80  public function getSize()
81  {
82  return (int) $this->getAttribute('size');
83  }
84 
90  public function getMaxlength()
91  {
92  return (int) $this->getAttribute('maxlength');
93  }
94 
100  public function getPlaceholder()
101  {
102  return (string) $this->getAttribute('placeholder');
103  }
104 
110  public function render()
111  {
112  if ($this->getSize() > $this->getMaxcols()) {
113  $maxcols = $this->getMaxcols();
114  } else {
115  $maxcols = $this->getSize();
116  }
117  $this->addAttribute('class', 'span' . $maxcols);
118  $dlist = $this->isDatalist();
119  if (!empty($dlist)) {
120  $this->addAttribute('list', 'list_' . $this->getName());
121  }
122 
124  return '<input ' . $attributes . 'value="'
125  . $this->getValue() . '" ' . $this->getExtra() .' >';
126  }
127 }
setValue($value)
Definition: Element.php:199
getValue($encode=false)
Definition: Element.php:180
setCaption($caption)
Definition: Element.php:396
setAttribute($name, $value=null)
Definition: Attributes.php:42
getMaxlength()
Definition: Text.php:90
__construct($caption, $name, $size, $maxlength, $value= '', $placeholder= '')
Definition: Text.php:62
getExtra($encode=false)
Definition: Element.php:539
getPlaceholder()
Definition: Text.php:100
addAttribute($name, $value)
Definition: Attributes.php:117