depage-forms
v2.0.0
html forms made easy
Toggle main menu visibility
Loading...
Searching...
No Matches
Boolean.php
Go to the documentation of this file.
1
<?php
2
10
11
namespace
Depage\HtmlForm\Elements;
12
13
use Depage\HtmlForm\Abstracts;
14
49
class
Boolean
extends
Abstracts\Input
50
{
60
protected
function
setDefaults
(): void
61
{
62
parent::setDefaults();
63
$this->defaults[
'defaultValue'
] =
false
;
64
$this->defaults[
'errorMessage'
] = _(
'Please check this box if you want to proceed'
);
65
}
66
72
public
function
__toString
(): string
73
{
74
$inputAttributes = $this->
htmlInputAttributes
();
75
$label
= $this->htmlLabel();
76
$marker
= $this->
htmlMarker
();
77
$wrapperAttributes = $this->
htmlWrapperAttributes
();
78
$errorMessage
= $this->
htmlErrorMessage
();
79
$helpMessage
= $this->
htmlHelpMessage
();
80
81
$selected =
''
;
82
if
(is_null($this->
getValue
()) && $this->defaultValue ===
true
) {
83
$selected =
" checked=\"yes\""
;
84
} elseif ($this->
getValue
() ===
true
) {
85
$selected =
" checked=\"yes\""
;
86
}
87
88
return
"<p {$wrapperAttributes}>"
.
89
"<label>"
.
90
"<input type=\"checkbox\" name=\"{$this->name}\"{$inputAttributes} value=\"true\"{$selected}>"
.
91
"<span class=\"depage-label\">{$label}{$marker}</span>"
.
92
"</label>"
.
93
$errorMessage
.
94
$helpMessage
.
95
"</p>\n"
;
96
}
97
107
public
function
validate
(): bool
108
{
109
if
(!$this->validated) {
110
$this->validated =
true
;
111
112
$this->valid = (
113
($this->value !==
null
)
114
&& ($this->validator->validate($this->value) || $this->
isEmpty
())
115
&& ($this->value || !$this->required)
116
);
117
}
118
119
return
$this->valid
;
120
}
121
131
public
function
setValue
(mixed $newValue): bool
132
{
133
if
(is_bool($newValue)) {
134
$this->value = $newValue;
135
} elseif ($newValue ===
"true"
) {
136
$this->value =
true
;
137
}
else
{
138
$this->value =
false
;
139
}
140
141
return
$this->value
;
142
}
143
}
144
145
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\HtmlForm\Abstracts\Element\$valid
$valid
Contains element validation status/result.
Definition
Element.php:41
Depage\HtmlForm\Abstracts\Input
input element base class
Definition
Input.php:22
Depage\HtmlForm\Abstracts\Input\htmlInputAttributes
htmlInputAttributes()
Returns string of HTML attributes for input element.
Definition
Input.php:576
Depage\HtmlForm\Abstracts\Input\$value
$value
Input elements's value.
Definition
Input.php:124
Depage\HtmlForm\Abstracts\Input\$label
$label
Input element - HTML label.
Definition
Input.php:37
Depage\HtmlForm\Abstracts\Input\$errorMessage
$errorMessage
Message that gets displayed in case of invalid input.
Definition
Input.php:218
Depage\HtmlForm\Abstracts\Input\htmlHelpMessage
htmlHelpMessage()
Returns HTML-rendered helpMessage.
Definition
Input.php:685
Depage\HtmlForm\Abstracts\Input\htmlWrapperAttributes
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
Definition
Input.php:636
Depage\HtmlForm\Abstracts\Input\htmlMarker
htmlMarker()
Returns elements' required-indicator.
Definition
Input.php:566
Depage\HtmlForm\Abstracts\Input\$helpMessage
$helpMessage
Extra help message.
Definition
Input.php:230
Depage\HtmlForm\Abstracts\Input\$marker
$marker
Input element - HTML marker text that marks required fields.
Definition
Input.php:92
Depage\HtmlForm\Abstracts\Input\getValue
getValue()
Returns the current input elements' value.
Definition
Input.php:402
Depage\HtmlForm\Abstracts\Input\isEmpty
isEmpty()
says wether the element value is empty
Definition
Input.php:368
Depage\HtmlForm\Abstracts\Input\htmlErrorMessage
htmlErrorMessage()
Returns HTML-rendered error message.
Definition
Input.php:666
Depage\HtmlForm\Elements\Boolean
HTML single checkbox input type.
Definition
Boolean.php:50
Depage\HtmlForm\Elements\Boolean\validate
validate()
validates boolean input element value
Definition
Boolean.php:107
Depage\HtmlForm\Elements\Boolean\setValue
setValue(mixed $newValue)
set the boolean element value
Definition
Boolean.php:131
Depage\HtmlForm\Elements\Boolean\__toString
__toString()
Renders element to HTML.
Definition
Boolean.php:72
Depage\HtmlForm\Elements\Boolean\setDefaults
setDefaults()
collects initial values across subclasses.
Definition
Boolean.php:60
Elements
Boolean.php
Generated on
for depage-forms by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net