Button
API reference › HTML › Form › Button
Renders the HTML <button> element.
Supports the experimental command and commandfor attributes. Availability and behavior may vary across browsers.
See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/button (BaseInline for the base implementation.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | UIAwesome\ |
$content protected | string | Content string assigned to the element. Default: ''. | UIAwesome\ |
$prefix protected | string | Prefix content string assigned to the element. Default: ''. | UIAwesome\ |
$prefixAttributes protected | array | HTML attributes array for the prefix element. Default: []. | UIAwesome\ |
$prefixTag protected | false|UnitEnum | Tag name for the prefix element, or false to disable. Default: false. | UIAwesome\ |
$suffix protected | string | Suffix content string assigned to the element. Default: ''. | UIAwesome\ |
$suffixAttributes protected | array | HTML attributes array for the suffix element. Default: []. | UIAwesome\ |
$suffixTag protected | false|UnitEnum | Tag name for the suffix element, or false to disable. Default: false. | UIAwesome\ |
$template protected | string | Template string used for constructing the HTML tag. Default: ''. | UIAwesome\ |
Methods
Section titled “Methods”Method details
Section titled “Method details”command()
Section titled “command() ”public function command(string|Stringable|UnitEnum|null $value): staticSets the command attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Command value, or null to remove the attribute. Accepts predefined values (‘show-modal’, ‘close’, ‘request-close’, ‘show-popover’, ‘hide-popover’, ‘toggle-popover’) or any custom value prefixed with ’—’. |
Returns
static: New instance with the updated command attribute. ButtonCommand for predefined enum values.
commandfor()
Section titled “commandfor() ”public function commandfor(string|Stringable|UnitEnum|null $value): staticSets the commandfor attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | ID of the element to control, or null to remove the attribute. |
Returns
static: New instance with the updated commandfor attribute.
form()
Section titled “form() ”public function form(string|Stringable|UnitEnum|null $value): staticSets the form attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Form ID, or null to remove the attribute. |
Returns
static: New instance with the updated form attribute.
formaction()
Section titled “formaction() ”public function formaction(string|Stringable|UnitEnum|null $value): staticSets the formaction attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | URL for form submission, or null to remove the attribute. |
Returns
static: New instance with the updated formaction attribute.
formenctype()
Section titled “formenctype() ”public function formenctype(string|Stringable|UnitEnum|null $value): staticSets the formenctype attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Encoding type for form submission, or null to remove the attribute. |
Returns
static: New instance with the updated formenctype attribute.
formmethod()
Section titled “formmethod() ”public function formmethod(string|Stringable|UnitEnum|null $value): staticSets the formmethod attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | HTTP method for form submission, or null to remove the attribute. |
Returns
static: New instance with the updated formmethod attribute.
formnovalidate()
Section titled “formnovalidate() ”public function formnovalidate(bool|null $value): staticSets the formnovalidate attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | bool| | Whether to bypass form validation, or null to remove the attribute. |
Returns
static: New instance with the updated formnovalidate attribute.
formtarget()
Section titled “formtarget() ”public function formtarget(string|Stringable|UnitEnum|null $value): staticSets the formtarget attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Browsing context for form submission response, or null to remove the attribute. |
Returns
static: New instance with the updated formtarget attribute.
popoverTarget()
Section titled “popoverTarget() ”public function popoverTarget(string|Stringable|UnitEnum|null $value): staticSets the popovertarget attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Popover target ID, or null to remove the attribute. |
Returns
static: New instance with the updated popovertarget attribute.
popoverTargetAction()
Section titled “popoverTargetAction() ”public function popoverTargetAction(string|Stringable|UnitEnum|null $value): staticSets the popovertargetaction attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Popover target action (‘hide’, ‘show’, ‘toggle’), or null to remove the attribute. |
Returns
static: New instance with the updated popovertargetaction attribute.
Throws
InvalidArgumentException: If the provided value is not valid.
type()
Section titled “type() ”public function type(string|UnitEnum|null $value): staticSets the type attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UnitEnum| | Button type (‘button’, ‘reset’, ‘submit’), or null to remove the attribute. |
Returns
static: New instance with the updated type attribute. ButtonType for predefined enum values.
Throws
InvalidArgumentException: if the provided value is not valid.
getTag()
Section titled “getTag() ”protected function getTag(): UIAwesome\Html\Interop\InlineReturns the tag enumeration for the <button> element.
run()
Section titled “run() ”protected function run(): stringRenders the <button> element with its content and attributes.
Returns
string: Rendered HTML for the <button> element.