Boolean.php
Go to the documentation of this file.
1<?php
11
13
49{
59 protected function setDefaults()
60 {
61 parent::setDefaults();
62 $this->defaults['defaultValue'] = false;
63 $this->defaults['errorMessage'] = _('Please check this box if you want to proceed');
64 }
65
71 public function __toString()
72 {
73 $inputAttributes = $this->htmlInputAttributes();
74 $label = $this->htmlLabel();
75 $marker = $this->htmlMarker();
76 $wrapperAttributes = $this->htmlWrapperAttributes();
79
80 $selected = ($this->htmlValue() === true) ? " checked=\"yes\"" : '';
81
82 return "<p {$wrapperAttributes}>" .
83 "<label>" .
84 "<input type=\"checkbox\" name=\"{$this->name}\"{$inputAttributes} value=\"true\"{$selected}>" .
85 "<span class=\"depage-label\">{$label}{$marker}</span>" .
86 "</label>" .
89 "</p>\n";
90 }
91
101 public function validate()
102 {
103 if (!$this->validated) {
104 $this->validated = true;
105
106 $this->valid = (($this->value !== null)
107 && ($this->validator->validate($this->value) || $this->isEmpty())
108 && ($this->value || !$this->required)
109 );
110 }
111
112 return $this->valid;
113 }
114
124 public function setValue($newValue)
125 {
126 if (is_bool($newValue)) {
127 $this->value = $newValue;
128 } elseif ($newValue === "true") {
129 $this->value = true;
130 } else {
131 $this->value = false;
132 }
133
134 return $this->value;
135 }
136}
137
138/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
$valid
Contains element validation status/result.
Definition Element.php:30
input element base class
Definition Input.php:21
htmlInputAttributes()
Returns string of HTML attributes for input element.
Definition Input.php:575
$value
Input elements's value.
Definition Input.php:123
$label
Input element - HTML label.
Definition Input.php:36
$errorMessage
Message that gets displayed in case of invalid input.
Definition Input.php:217
htmlHelpMessage()
Returns HTML-rendered helpMessage.
Definition Input.php:676
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
Definition Input.php:627
htmlMarker()
Returns elements' required-indicator.
Definition Input.php:565
$helpMessage
Extra help message.
Definition Input.php:229
htmlValue()
Returns HTML-rendered element value.
Definition Input.php:647
$marker
Input element - HTML marker text that marks required fields.
Definition Input.php:91
isEmpty()
says wether the element value is empty
Definition Input.php:368
htmlErrorMessage()
Returns HTML-rendered error message.
Definition Input.php:657
HTML single checkbox input type.
Definition Boolean.php:49
validate()
validates boolean input element value
Definition Boolean.php:101
__toString()
Renders element to HTML.
Definition Boolean.php:71
setValue($newValue)
set the boolean element value
Definition Boolean.php:124
setDefaults()
collects initial values across subclasses.
Definition Boolean.php:59
Abstract element classes.
Definition Container.php:10
Classes for HTML input-elements.
Definition Address.php:9