depage-forms v1.4.1
html forms made easy
Loading...
Searching...
No Matches
Button.php
Go to the documentation of this file.
1<?php
2
10
11namespace Depage\HtmlForm\Elements;
12
13use Depage\HtmlForm\Abstracts;
14
40{
41 protected $defaultValue = "";
42
52 protected function setDefaults(): void
53 {
54 parent::setDefaults();
55
56 $this->defaults['defaultValue'] = false;
57 }
58
68 public function setValue(mixed $newValue): bool
69 {
70 if (is_bool($newValue)) {
71 $this->value = $newValue;
72 } elseif ($newValue === "true") {
73 $this->value = true;
74 } else {
75 $this->value = false;
76 }
77
78 return $this->value;
79 }
80
86 public function __toString(): string
87 {
88 $value = "true";
89 $type = "submit";
90 $inputAttributes = $this->htmlInputAttributes();
91 $marker = $this->htmlMarker();
92 $label = $this->htmlLabel();
93 $wrapperAttributes = $this->htmlWrapperAttributes();
96
97 return "<p {$wrapperAttributes}>" .
98 "<button name=\"{$this->name}\" type=\"submit\"{$inputAttributes} value=\"{$value}\">{$label}</button>" .
101 "</p>\n";
102 }
103}
104
105/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
input element base class
Definition Input.php:22
htmlInputAttributes()
Returns string of HTML attributes for input element.
Definition Input.php:576
$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
$type
Input element type - HTML input type attribute.
Definition Input.php:26
$helpMessage
Extra help message.
Definition Input.php:230
$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 Button.php:40
setValue(mixed $newValue)
set the boolean element value
Definition Button.php:68
__toString()
Renders element to HTML.
Definition Button.php:86
setDefaults()
collects initial values across subclasses
Definition Button.php:52