depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
Textarea.php
Go to the documentation of this file.
1<?php
2
10
11namespace Depage\HtmlForm\Elements;
12
35class Textarea extends Text
36{
40 protected $rows;
41
45 protected $cols;
46
50 protected $autogrow = false;
60 protected function setDefaults(): void
61 {
62 parent::setDefaults();
63
64 $this->defaults['rows'] = null;
65 $this->defaults['cols'] = null;
66 $this->defaults['autogrow'] = false;
67 }
68
74 public function __toString(): string
75 {
76 $label = $this->htmlLabel();
77 $marker = $this->htmlMarker();
78 $inputAttributes = $this->htmlInputAttributes();
79 $value = $this->htmlValue();
80 $rows = $this->htmlRows();
81 $cols = $this->htmlCols();
82 $wrapperAttributes = $this->htmlWrapperAttributes();
85
86 return "<p {$wrapperAttributes}>" .
87 "<label>" .
88 "<span class=\"depage-label\">{$label}{$marker}</span>" .
89 "<textarea name=\"{$this->name}\"{$inputAttributes}{$rows}{$cols}>{$value}</textarea>" .
90 "</label>" .
93 "</p>\n";
94 }
95
99 protected function htmlDataAttributes(): string
100 {
101 $options = [];
102 $options['autogrow'] = $this->autogrow;
103
104 $this->dataAttr['textarea-options'] = json_encode($options);
105
106 return parent::htmlDataAttributes();
107 }
108
114 protected function htmlRows(): string
115 {
116 return ($this->rows === null) ? "" : " rows=\"" . $this->htmlEscape($this->rows) . "\"";
117 }
118
123 protected function htmlCols(): string
124 {
125 return ($this->cols === null) ? "" : " cols=\"" . $this->htmlEscape($this->cols) . "\"";
126 }
127}
128
129/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
Definition Element.php:261
$value
Input elements's value.
Definition Input.php:124
$label
Input element - HTML label.
Definition Input.php:37
$errorMessage
Message that gets displayed in case of invalid input.
Definition Input.php:218
htmlHelpMessage()
Returns HTML-rendered helpMessage.
Definition Input.php:685
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
Definition Input.php:636
htmlMarker()
Returns elements' required-indicator.
Definition Input.php:566
$helpMessage
Extra help message.
Definition Input.php:230
htmlValue()
Returns HTML-rendered element value.
Definition Input.php:656
$marker
Input element - HTML marker text that marks required fields.
Definition Input.php:92
htmlErrorMessage()
Returns HTML-rendered error message.
Definition Input.php:666
HTML text input type.
Definition Text.php:40
htmlInputAttributes()
renders text element specific HTML attributes
Definition Text.php:160
HTML textarea element.
Definition Textarea.php:36
htmlCols()
Renders HTML cols attribute.
Definition Textarea.php:123
$autogrow
wether to autogrow textarea or not
Definition Textarea.php:50
htmlDataAttributes()
Returns dataAttr escaped as attribute string.
Definition Textarea.php:99
htmlRows()
Renders HTML rows attribute.
Definition Textarea.php:114
__toString()
Renders element to HTML.
Definition Textarea.php:74
$cols
HTML cols attribute.
Definition Textarea.php:45
setDefaults()
collects initial values across subclasses
Definition Textarea.php:60
$rows
HTML rows attribute.
Definition Textarea.php:40