depage-forms
v2.0.0
html forms made easy
Toggle main menu visibility
Loading...
Searching...
No Matches
Fieldset.php
Go to the documentation of this file.
1
<?php
2
10
11
namespace
Depage\HtmlForm\Elements;
12
13
use Depage\HtmlForm\Abstracts;
14
50
51
class
Fieldset
extends
Abstracts\Container
52
{
56
protected
$form
;
57
61
protected
$label
;
62
66
protected
$disabled
;
67
71
protected
$required
;
72
82
protected
function
setDefaults
(): void
83
{
84
parent::setDefaults();
85
86
$this->defaults[
'label'
] =
$this->name
;
87
$this->defaults[
'disabled'
] =
false
;
88
$this->defaults[
'required'
] =
false
;
89
}
90
105
public
function
addElement
(
string
$type,
string
$name
, array $parameters): object
106
{
107
$this->form->checkElementName(
$name
);
108
109
$newElement = parent::addElement($type,
$name
, $parameters);
110
111
if
(!($newElement instanceof
Fieldset
)) {
112
$this->form->updateInputValue(
$name
);
113
}
114
115
return
$newElement;
116
}
117
123
protected
function
htmlClasses
(): string
124
{
125
$classes =
''
;
126
127
if
($this->required) {
128
$classes .=
' required'
;
129
}
130
if
($this->disabled) {
131
$classes .=
' disabled'
;
132
}
133
if
(!empty($this->
class
)) {
134
$classes .=
' '
. $this->
htmlEscape
($this->
class
);
135
}
136
137
return
trim($classes);
138
}
139
147
public
function
__toString
(): string
148
{
149
$renderedElements =
''
;
150
$formName = $this->form->getName();
151
$label
= $this->htmlLabel();
152
$classes = $this->
htmlClasses
();
153
154
$htmlAttributes =
"id=\"{$formName}-{$this->name}\""
;
155
$htmlAttributes .=
" name=\"{$this->name}\""
;
156
$htmlAttributes .= $this->
htmlDataAttributes
();
157
158
if
(!empty($classes)) {
159
$htmlAttributes .=
" class=\""
. $classes .
"\""
;
160
}
161
162
163
foreach
($this->elementsAndHtml as $element) {
164
$renderedElements .= $element;
165
}
166
167
return
"<fieldset {$htmlAttributes}>"
.
168
"<legend><span>{$label}</span></legend>{$renderedElements}"
.
169
"</fieldset>\n"
;
170
}
171
}
172
173
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\HtmlForm\Abstracts\Container
container element base class
Definition
Container.php:60
Depage\HtmlForm\Abstracts\Element\htmlDataAttributes
htmlDataAttributes()
Returns dataAttr escaped as attribute string.
Definition
Element.php:302
Depage\HtmlForm\Abstracts\Element\$name
$name
Element name.
Definition
Element.php:36
Depage\HtmlForm\Abstracts\Element\htmlEscape
htmlEscape(array|string $options=[])
Escapes HTML in strings and arrays of strings.
Definition
Element.php:263
Depage\HtmlForm\Elements\Fieldset
The fieldset class holds HTML-fieldset specific attributes and methods.
Definition
Fieldset.php:52
Depage\HtmlForm\Elements\Fieldset\$label
$label
label text
Definition
Fieldset.php:61
Depage\HtmlForm\Elements\Fieldset\$form
$form
parent HTML form.
Definition
Fieldset.php:56
Depage\HtmlForm\Elements\Fieldset\$required
$required
HTML required attribute.
Definition
Fieldset.php:71
Depage\HtmlForm\Elements\Fieldset\$disabled
$disabled
HTML disabled attribute.
Definition
Fieldset.php:66
Depage\HtmlForm\Elements\Fieldset\__toString
__toString()
Renders the fieldset to HTML code.
Definition
Fieldset.php:147
Depage\HtmlForm\Elements\Fieldset\htmlClasses
htmlClasses()
Returns string of the elements' HTML-classes, separated by spaces.
Definition
Fieldset.php:123
Depage\HtmlForm\Elements\Fieldset\setDefaults
setDefaults()
collects initial values across subclasses.
Definition
Fieldset.php:82
Depage\HtmlForm\Elements\Fieldset\addElement
addElement(string $type, string $name, array $parameters)
Generates sub-elements.
Definition
Fieldset.php:105
Elements
Fieldset.php
Generated on
for depage-forms by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net