Final Class Yiisoft\Form\Field\SubmitButton
| Inheritance | Yiisoft\Form\Field\SubmitButton » Yiisoft\Form\Field\Base\ButtonField » Yiisoft\Form\Field\Base\PartsField » Yiisoft\Form\Field\Base\BaseField » Yiisoft\Widget\Widget |
|---|---|
| Uses Traits | Yiisoft\Form\Field\Base\FieldContentTrait |
Represents <button> element of type "submit" are rendered as button for submitting a form.
Protected Properties
Public Methods
Protected Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| BUILTIN_TOKENS | [ '{input}', '{label}', '{hint}', '{error}', ] | Yiisoft\Form\Field\Base\PartsField |
Method Details
| public addButtonAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addButtonAttributes(array $attributes): static
{
$new = clone $this;
$new->buttonAttributes = array_merge($this->buttonAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::addButtonClass()
Add one or more CSS classes to the button tag.
| public addButtonClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addButtonClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->buttonAttributes, $class);
return $new;
}
| public addContainerAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addContainerAttributes(array $attributes): static
{
$new = clone $this;
$new->containerAttributes = array_merge($new->containerAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\BaseField::addContainerClass()
Add one or more CSS classes to the container tag.
| public addContainerClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addContainerClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->containerAttributes, $class);
return $new;
}
| public addContent( string|\Stringable $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|\Stringable |
Field content. |
final public function addContent(string|Stringable ...$content): static
{
$new = clone $this;
$new->content = array_merge($new->content, array_values($content));
return $new;
}
| public addErrorAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addErrorAttributes(array $attributes): static
{
$new = clone $this;
$new->errorAttributes = array_merge($new->errorAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::addErrorClass()
Add one or more CSS classes to the error tag.
| public addErrorClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addErrorClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->errorAttributes, $class);
return $new;
}
| public addHintAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addHintAttributes(array $attributes): static
{
$new = clone $this;
$new->hintAttributes = array_merge($new->hintAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::addHintClass()
Add one or more CSS classes to the hint tag.
| public addHintClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addHintClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->hintAttributes, $class);
return $new;
}
| public addInputContainerAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addInputContainerAttributes(array $attributes): static
{
$new = clone $this;
$new->inputContainerAttributes = array_merge($new->inputContainerAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::addInputContainerClass()
Add one or more CSS classes to the input container tag.
| public addInputContainerClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addInputContainerClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->inputContainerAttributes, $class);
return $new;
}
| public addLabelAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function addLabelAttributes(array $attributes): static
{
$new = clone $this;
$new->labelAttributes = array_merge($new->labelAttributes, $attributes);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::addLabelClass()
Add one or more CSS classes to the label tag.
| public addLabelClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function addLabelClass(?string ...$class): static
{
$new = clone $this;
Html::addCssClass($new->labelAttributes, $class);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::afterInput()
| public afterInput( string|\Stringable $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|\Stringable | |
final public function afterInput(string|Stringable $content): static
{
$new = clone $this;
$new->afterInput = $content;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::ariaDescribedBy()
Identifies the element (or elements) that describes the object.
| public ariaDescribedBy( string|null $value ): Yiisoft\Form\Field\SubmitButton | ||
| $value | string|null | |
final public function ariaDescribedBy(?string ...$value): static
{
$new = clone $this;
$new->buttonAttributes['aria-describedby'] = array_filter($value, static fn(?string $v): bool => $v !== null);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::ariaLabel()
Defines a string value that labels the current element.
| public ariaLabel( string|null $value ): Yiisoft\Form\Field\SubmitButton | ||
| $value | string|null | |
final public function ariaLabel(?string $value): static
{
$new = clone $this;
$new->buttonAttributes['aria-label'] = $value;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::autofocus()
Focus on the control (put cursor into it) when the page loads. Only one form element could be in focus at the same time.
| public autofocus( boolean $value = true ): Yiisoft\Form\Field\SubmitButton | ||
| $value | boolean | |
final public function autofocus(bool $value = true): static
{
$new = clone $this;
$new->buttonAttributes['autofocus'] = $value;
return $new;
}
| public beforeInput( string|\Stringable $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|\Stringable | |
final public function beforeInput(string|Stringable $content): static
{
$new = clone $this;
$new->beforeInput = $content;
return $new;
}
| protected beforeRender( ): void |
protected function beforeRender(): void {}
Defined in: Yiisoft\Form\Field\Base\BaseField::begin()
| public begin( ): string|null |
final public function begin(): ?string
{
parent::begin();
$this->isStartedByBegin = true;
$this->beforeRender();
$content = $this->generateBeginContent();
return $this->renderOpenContainerAndContent($content);
}
| public containerAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function containerAttributes(array $attributes): static
{
$new = clone $this;
$new->containerAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\BaseField::containerClass()
Replace container tag CSS classes with a new set of classes.
| public containerClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function containerClass(?string ...$class): static
{
$new = clone $this;
$new->containerAttributes['class'] = array_filter($class, static fn($c) => $c !== null);
return $new;
}
Defined in: Yiisoft\Form\Field\Base\BaseField::containerId()
Set container tag ID.
| public containerId( string|null $id ): Yiisoft\Form\Field\SubmitButton | ||
| $id | string|null |
Container tag ID. |
final public function containerId(?string $id): static
{
$new = clone $this;
$new->containerAttributes['id'] = $id;
return $new;
}
| public containerTag( string $tag ): Yiisoft\Form\Field\SubmitButton | ||
| $tag | string | |
final public function containerTag(string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->containerTag = $tag;
return $new;
}
| public content( string|\Stringable $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|\Stringable |
Field content. |
final public function content(string|Stringable ...$content): static
{
$new = clone $this;
$new->content = $content;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::disabled()
| public disabled( boolean $disabled = true ): Yiisoft\Form\Field\SubmitButton | ||
| $disabled | boolean | |
final public function disabled(bool $disabled = true): static
{
$new = clone $this;
$new->buttonAttributes['disabled'] = $disabled;
return $new;
}
| public doubleEncodeContent( boolean $doubleEncode ): Yiisoft\Form\Field\SubmitButton | ||
| $doubleEncode | boolean |
Whether already encoded HTML entities in field content should be encoded.
Defaults to |
final public function doubleEncodeContent(bool $doubleEncode): static
{
$new = clone $this;
$new->doubleEncodeContent = $doubleEncode;
return $new;
}
| public encodeContent( boolean|null $encode ): Yiisoft\Form\Field\SubmitButton | ||
| $encode | boolean|null |
Whether to encode field content. Supported values:
|
final public function encodeContent(?bool $encode): static
{
$new = clone $this;
$new->encodeContent = $encode;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::error()
| public error( string|null $message, string $messages ): Yiisoft\Form\Field\SubmitButton | ||
| $message | string|null | |
| $messages | string | |
final public function error(?string $message, string ...$messages): static
{
$new = clone $this;
$new->errorConfig['message()'] = [$message, ...$messages];
return $new;
}
| public errorAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function errorAttributes(array $attributes): static
{
$new = clone $this;
$new->errorAttributes = $attributes;
$new->replaceErrorAttributes = true;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::errorClass()
Replace error tag CSS classes with a new set of classes.
| public errorClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function errorClass(?string ...$class): static
{
$new = clone $this;
$new->errorAttributes['class'] = $class;
$new->replaceErrorClass = true;
return $new;
}
| public errorConfig( array $config ): Yiisoft\Form\Field\SubmitButton | ||
| $config | array | |
final public function errorConfig(array $config): static
{
$new = clone $this;
$new->errorConfig = $config;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::errorId()
Set error tag ID.
| public errorId( string|null $id ): Yiisoft\Form\Field\SubmitButton | ||
| $id | string|null |
Error tag ID. |
final public function errorId(?string $id): static
{
$new = clone $this;
$new->errorAttributes['id'] = $id;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::form()
Specifies the form element the button belongs to. The value of this attribute must be the ID attribute of a form element in the same document.
| public form( string|null $id ): Yiisoft\Form\Field\SubmitButton | ||
| $id | string|null |
ID of a form. |
final public function form(?string $id): static
{
$new = clone $this;
$new->buttonAttributes['form'] = $id;
return $new;
}
| protected generateBeginContent( ): string |
final protected function generateBeginContent(): string
{
$parts = [
'{input}' => $this->generateBeginInput(),
'{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
'{hint}' => $this->generateHint(),
'{error}' => $this->generateError(),
];
return $this->makeContent($this->templateBegin, $parts);
}
| protected generateBeginInput( ): string |
protected function generateBeginInput(): string
{
return '';
}
| protected generateContent( ): string|null |
final protected function generateContent(): ?string
{
$parts = [
'{input}' => $this->generateInputContainerBegin()
. $this->beforeInput
. $this->generateInput()
. $this->afterInput
. $this->generateInputContainerEnd(),
'{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
'{hint}' => $this->generateHint(),
'{error}' => $this->generateError(),
];
return $this->makeContent($this->template, $parts);
}
| protected generateEndContent( ): string |
final protected function generateEndContent(): string
{
$parts = [
'{input}' => $this->generateEndInput(),
'{label}' => ($this->hideLabel ?? $this->shouldHideLabel()) ? '' : $this->generateLabel(),
'{hint}' => $this->generateHint(),
'{error}' => $this->generateError(),
];
return $this->makeContent($this->templateEnd, $parts);
}
| protected generateEndInput( ): string |
protected function generateEndInput(): string
{
return '';
}
| protected generateInput( ): string |
final protected function generateInput(): string
{
$button = ($this->button ?? Button::tag())
->type($this->getType());
if (!empty($this->buttonAttributes)) {
$button = $button->addAttributes($this->buttonAttributes);
}
$content = $this->renderContent();
if ($content !== '') {
$button = $button->content($content);
}
return $button->render();
}
| protected static getThemeConfig( string|null $theme ): array | ||
| $theme | string|null | |
final protected static function getThemeConfig(?string $theme): array
{
return ThemeContainer::getTheme($theme)?->getFieldConfig(static::class) ?? [];
}
| protected hasCustomError( ): boolean |
final protected function hasCustomError(): bool
{
return isset($this->errorConfig['message()']);
}
Defined in: Yiisoft\Form\Field\Base\PartsField::hideLabel()
| public hideLabel( boolean|null $hide = true ): Yiisoft\Form\Field\SubmitButton | ||
| $hide | boolean|null | |
final public function hideLabel(?bool $hide = true): static
{
$new = clone $this;
$new->hideLabel = $hide;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::hint()
| public hint( string|null $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|null | |
final public function hint(?string $content): static
{
$new = clone $this;
$new->hintConfig['content()'] = [$content];
return $new;
}
| public hintAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function hintAttributes(array $attributes): static
{
$new = clone $this;
$new->hintAttributes = $attributes;
$new->replaceHintAttributes = true;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::hintClass()
Replace hint tag CSS classes with a new set of classes.
| public hintClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function hintClass(?string ...$class): static
{
$new = clone $this;
$new->hintAttributes['class'] = $class;
$new->replaceHintClass = true;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::hintConfig()
| public hintConfig( array $config ): Yiisoft\Form\Field\SubmitButton | ||
| $config | array | |
final public function hintConfig(array $config): static
{
$new = clone $this;
$new->hintConfig = $config;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::hintId()
Set hint tag ID.
| public hintId( string|null $id ): Yiisoft\Form\Field\SubmitButton | ||
| $id | string|null |
Hint tag ID. |
final public function hintId(?string $id): static
{
$new = clone $this;
$new->hintAttributes['id'] = $id;
return $new;
}
| public inputContainerAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function inputContainerAttributes(array $attributes): static
{
$new = clone $this;
$new->inputContainerAttributes = $attributes;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::inputContainerClass()
Replace input container tag CSS classes with a new set of classes.
| public inputContainerClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function inputContainerClass(?string ...$class): static
{
$new = clone $this;
$new->inputContainerAttributes['class'] = array_filter($class, static fn($c) => $c !== null);
return $new;
}
| public inputContainerTag( string|null $tag ): Yiisoft\Form\Field\SubmitButton | ||
| $tag | string|null | |
final public function inputContainerTag(?string $tag): static
{
if ($tag === '') {
throw new InvalidArgumentException('Tag name cannot be empty.');
}
$new = clone $this;
$new->inputContainerTag = $tag;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::label()
| public label( string|null $content ): Yiisoft\Form\Field\SubmitButton | ||
| $content | string|null | |
final public function label(?string $content): static
{
$new = clone $this;
$new->label = $content;
return $new;
}
| public labelAttributes( array $attributes ): Yiisoft\Form\Field\SubmitButton | ||
| $attributes | array | |
final public function labelAttributes(array $attributes): static
{
$new = clone $this;
$new->labelAttributes = $attributes;
$new->replaceLabelAttributes = true;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::labelClass()
Replace label tag CSS classes with a new set of classes.
| public labelClass( string|null $class ): Yiisoft\Form\Field\SubmitButton | ||
| $class | string|null |
One or many CSS classes. |
final public function labelClass(?string ...$class): static
{
$new = clone $this;
$new->labelAttributes['class'] = $class;
$new->replaceLabelClass = true;
return $new;
}
| public labelConfig( array $config ): Yiisoft\Form\Field\SubmitButton | ||
| $config | array | |
final public function labelConfig(array $config): static
{
$new = clone $this;
$new->labelConfig = $config;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::labelId()
Set label tag ID.
| public labelId( string|null $id ): Yiisoft\Form\Field\SubmitButton | ||
| $id | string|null |
Label tag ID. |
final public function labelId(?string $id): static
{
$new = clone $this;
$new->labelAttributes['id'] = $id;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::name()
| public name( string|null $name ): self | ||
| $name | string|null | |
final public function name(?string $name): self
{
$new = clone $this;
$new->buttonAttributes['name'] = $name;
return $new;
}
| protected prepareContainerAttributes( array &$attributes ): void | ||
| $attributes | array | |
protected function prepareContainerAttributes(array &$attributes): void {}
Defined in: Yiisoft\Form\Field\Base\BaseField::render()
| public render( ): string |
final public function render(): string
{
if ($this->isStartedByBegin) {
$this->isStartedByBegin = false;
return $this->renderEnd();
}
$this->beforeRender();
$content = $this->generateContent();
if ($content === null) {
$this->enrichment = [];
return '';
}
$result = $this->renderOpenContainerAndContent($content);
if ($this->useContainer) {
$result .= "\n" . Html::closeTag($this->containerTag);
}
$this->enrichment = [];
return $result;
}
| protected renderContent( ): string | ||
| return | string |
Obtain field content considering encoding options encodeContent(). |
|---|---|---|
final protected function renderContent(): string
{
$content = '';
foreach ($this->content as $item) {
if ($this->encodeContent || ($this->encodeContent === null && !($item instanceof NoEncodeStringableInterface))) {
$item = Html::encode($item, $this->doubleEncodeContent);
}
$content .= $item;
}
return $content;
}
| protected renderError( Yiisoft\Form\Field\Part\Error $error ): string | ||
| $error | Yiisoft\Form\Field\Part\Error | |
protected function renderError(Error $error): string
{
return $error->render();
}
Defined in: Yiisoft\Form\Field\Base\PartsField::renderHint()
| protected renderHint( Yiisoft\Form\Field\Part\Hint $hint ): string | ||
| $hint | Yiisoft\Form\Field\Part\Hint | |
protected function renderHint(Hint $hint): string
{
return $hint->render();
}
| protected renderLabel( Yiisoft\Form\Field\Part\Label $label ): string | ||
| $label | Yiisoft\Form\Field\Part\Label | |
protected function renderLabel(Label $label): string
{
return $label->render();
}
| protected shouldHideLabel( ): boolean |
protected function shouldHideLabel(): bool
{
return false;
}
Defined in: Yiisoft\Form\Field\Base\ButtonField::tabIndex()
The tabindex attribute indicates that its element can be focused, and where it participates in sequential
keyboard navigation (usually with the Tab key, hence the name).
It accepts an integer as a value, with different results depending on the integer's value:
- A negative value (usually
tabindex="-1") means that the element is not reachable via sequential keyboard navigation, but could be focused with Javascript or visually. It's mostly useful to create accessible widgets with JavaScript. tabindex="0"means that the element should be focusable in sequential keyboard navigation, but its order is defined by the document's source order.- A positive value means the element should be focusable in sequential keyboard navigation, with its order
defined by the value of the number. That is,
tabindex="4"is focused beforetabindex="5", but aftertabindex="3".
| public tabIndex( integer|null $value ): Yiisoft\Form\Field\SubmitButton | ||
| $value | integer|null | |
final public function tabIndex(?int $value): static
{
$new = clone $this;
$new->buttonAttributes['tabindex'] = $value;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::template()
Set layout template for render a field.
| public template( string $template ): Yiisoft\Form\Field\SubmitButton | ||
| $template | string | |
final public function template(string $template): static
{
$new = clone $this;
$new->template = $template;
return $new;
}
| public templateBegin( string $template ): Yiisoft\Form\Field\SubmitButton | ||
| $template | string | |
final public function templateBegin(string $template): static
{
$new = clone $this;
$new->templateBegin = $template;
return $new;
}
| public templateEnd( string $template ): Yiisoft\Form\Field\SubmitButton | ||
| $template | string | |
final public function templateEnd(string $template): static
{
$new = clone $this;
$new->templateEnd = $template;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::token()
| public token( string $token, string|\Stringable $value ): Yiisoft\Form\Field\SubmitButton | ||
| $token | string | |
| $value | string|\Stringable | |
final public function token(string $token, string|Stringable $value): static
{
$this->validateToken($token);
$new = clone $this;
$new->extraTokens[$token] = $value;
return $new;
}
Defined in: Yiisoft\Form\Field\Base\PartsField::tokens()
| public tokens( array $tokens ): Yiisoft\Form\Field\SubmitButton | ||
| $tokens | array | |
final public function tokens(array $tokens): static
{
$new = clone $this;
foreach ($tokens as $token => $value) {
if (!is_string($token)) {
throw new InvalidArgumentException(
sprintf(
'Token should be string. %s given.',
get_debug_type($token),
),
);
}
if (!is_string($value) && !$value instanceof Stringable) {
throw new InvalidArgumentException(
sprintf(
'Token value should be string or Stringable. %s given.',
get_debug_type($value),
),
);
}
$this->validateToken($token);
$new->extraTokens[$token] = $value;
}
return $new;
}
| public useContainer( boolean $use ): Yiisoft\Form\Field\SubmitButton | ||
| $use | boolean | |
final public function useContainer(bool $use): static
{
$new = clone $this;
$new->useContainer = $use;
return $new;
}
Signup or Login in order to comment.