11namespace Depage\HtmlForm\Elements;
13use Depage\HtmlForm\Abstracts;
71 parent::__construct(
$name, $parameters, $form);
73 $this->list = (isset($parameters[
'list']) && is_array($parameters[
'list'])) ? $parameters[
'list'] :
false;
87 parent::setDefaults();
90 $this->defaults[
'defaultValue'] =
'';
91 $this->defaults[
'placeholder'] =
false;
92 $this->defaults[
'maxlength'] =
false;
93 $this->defaults[
'normalize'] =
true;
104 $type = strtolower($this->type);
107 $label = $this->htmlLabel();
113 return "<p {$wrapperAttributes}>" .
115 "<span class=\"depage-label\">{$label}{$marker}</span>" .
116 "<input name=\"{$this->name}\" type=\"{$type}\"{$inputAttributes} value=\"{$value}\">" .
132 if ($this->list && is_array($this->list)) {
136 $htmlList =
"<datalist id=\"{$formName}-{$this->name}-list\">";
138 foreach ($options as $index => $option) {
140 if (is_int($index)) {
141 $htmlList .=
"<option value=\"{$option}\">";
143 $htmlList .=
"<option value=\"{$index}\" label=\"{$option}\">";
147 $htmlList .=
"</datalist>";
162 $attributes = parent::htmlInputAttributes();
164 if ($this->maxlength) {
165 $attributes .=
" maxlength=\"{$this->maxlength}\"";
167 if ($this->placeholder) {
168 $attributes .=
" placeholder=\"{$this->placeholder}\"";
171 $attributes .=
" list=\"{$this->formName}-{$this->name}-list\"";
174 $attributes .= $this->validator->getPatternAttribute();
187 $this->value = preg_replace(
'/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u',
'', (
string) $this->value);
189 if ($this->normalize && class_exists(
"\\Normalizer")) {
190 $this->value = \Normalizer::normalize($this->value);
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
$value
Input elements's value.
$formName
Name of the parent HTML form.
$label
Input element - HTML label.
$errorMessage
Message that gets displayed in case of invalid input.
htmlHelpMessage()
Returns HTML-rendered helpMessage.
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
htmlMarker()
Returns elements' required-indicator.
$type
Input element type - HTML input type attribute.
$helpMessage
Extra help message.
htmlValue()
Returns HTML-rendered element value.
$marker
Input element - HTML marker text that marks required fields.
htmlErrorMessage()
Returns HTML-rendered error message.
htmlInputAttributes()
renders text element specific HTML attributes
$normalize
wether to normalize unicode strings or not
__construct($name, $parameters, $form)
text class constructor
typeCastValue()
Converts value to element specific type.
__toString()
Renders element to HTML.
$placeholder
HTML placeholder attribute.
setDefaults()
collects initial values across subclasses
htmlList($options=null)
Renders HTML datalist.
$maxlength
HTML maxlength attribute.