0 follower

Final Class Yiisoft\Html\Tag\Input

InheritanceYiisoft\Html\Tag\Input » Yiisoft\Html\Tag\Base\InputTag » Yiisoft\Html\Tag\Base\VoidTag » Yiisoft\Html\Tag\Base\Tag
ImplementsYiisoft\Html\NoEncodeStringableInterface

HTML input.

Protected Properties

Hide inherited properties

Property Type Description Defined By
$attributes array Yiisoft\Html\Tag\Base\Tag

Public Methods

Hide inherited methods

Method Description Defined By
__toString() Yiisoft\Html\Tag\Base\Tag
addAttributes() Add a set of attributes to existing tag attributes. Yiisoft\Html\Tag\Base\Tag
addClass() Add one or more CSS classes to the tag. Yiisoft\Html\Tag\Base\Tag
addStyle() Add CSS styles to the tag. Yiisoft\Html\Tag\Base\Tag
attribute() Set attribute value. Yiisoft\Html\Tag\Base\Tag
attributes() Replace attributes with a new set. Yiisoft\Html\Tag\Base\Tag
button() Button. Yiisoft\Html\Tag\Input
checkbox() Checkbox input. Yiisoft\Html\Tag\Input
class() Replace current tag CSS classes with a new set of classes. Yiisoft\Html\Tag\Base\Tag
color() Color. Yiisoft\Html\Tag\Input
disabled() Yiisoft\Html\Tag\Base\InputTag
file() File input. Yiisoft\Html\Tag\Input
form() Yiisoft\Html\Tag\Base\InputTag
hidden() Hidden input. Yiisoft\Html\Tag\Input
id() Set tag ID. Yiisoft\Html\Tag\Base\Tag
name() Yiisoft\Html\Tag\Base\InputTag
password() Password input. Yiisoft\Html\Tag\Input
radio() Radio input. Yiisoft\Html\Tag\Input
range() Range. Yiisoft\Html\Tag\Input
readonly() Yiisoft\Html\Tag\Base\InputTag
removeStyle() Remove CSS styles from the tag. Yiisoft\Html\Tag\Base\Tag
render() Yiisoft\Html\Tag\Base\Tag
required() Yiisoft\Html\Tag\Base\InputTag
resetButton() Reset button. Yiisoft\Html\Tag\Input
submitButton() Submit button. Yiisoft\Html\Tag\Input
tag() Yiisoft\Html\Tag\Base\VoidTag
text() Text input. Yiisoft\Html\Tag\Input
type() Input with the type specified. Yiisoft\Html\Tag\Input
unionAttributes() Union attributes with a new set. Yiisoft\Html\Tag\Base\Tag
value() Yiisoft\Html\Tag\Base\InputTag

Method Details

Hide inherited methods

__toString() public method
public __toString( ): string

                final public function __toString(): string
{
    return $this->render();
}

            
addAttributes() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::addAttributes()

Add a set of attributes to existing tag attributes.

Same named attributes are replaced.

public addAttributes( array $attributes ): Yiisoft\Html\Tag\Input
$attributes array

Name-value set of attributes.

                final public function addAttributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes = array_merge($new->attributes, $attributes);
    return $new;
}

            
addClass() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::addClass()

Add one or more CSS classes to the tag.

public addClass( \BackedEnum|string|null $class ): Yiisoft\Html\Tag\Input
$class \BackedEnum|string|null

One or many CSS classes.

                final public function addClass(BackedEnum|string|null ...$class): static
{
    $new = clone $this;
    Html::addCssClass($new->attributes, $class);
    return $new;
}

            
addStyle() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::addStyle()

Add CSS styles to the tag.

See also Yiisoft\Html\Html::addCssStyle().

public addStyle( string|string[] $style, boolean $overwrite true ): Yiisoft\Html\Tag\Input
$style string|string[]

The new style string (e.g. 'width: 100px; height: 200px') or array (e.g. ['width' => '100px', 'height' => '200px']).

$overwrite boolean

Whether to overwrite existing CSS properties if the new style contain them too.

                final public function addStyle(array|string $style, bool $overwrite = true): static
{
    $new = clone $this;
    Html::addCssStyle($new->attributes, $style, $overwrite);
    return $new;
}

            
after() protected method
protected after( ): string

                protected function after(): string
{
    return '';
}

            
attribute() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::attribute()

Set attribute value.

public attribute( string $name, mixed $value ): Yiisoft\Html\Tag\Input
$name string

Name of the attribute.

$value mixed

Value of the attribute.

                final public function attribute(string $name, mixed $value): static
{
    $new = clone $this;
    $new->attributes[$name] = $value;
    return $new;
}

            
attributes() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::attributes()

Replace attributes with a new set.

public attributes( array $attributes ): Yiisoft\Html\Tag\Input
$attributes array

Name-value set of attributes.

                final public function attributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes = $attributes;
    return $new;
}

            
before() protected method
protected before( ): string

                protected function before(): string
{
    return '';
}

            
button() public static method

Button.

public static button( string|null $label null ): self
$label string|null

Button label.

                public static function button(?string $label = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'button';
    $input->attributes['value'] = $label;
    return $input;
}

            
checkbox() public static method

Checkbox input.

public static checkbox( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): Yiisoft\Html\Tag\Input\Checkbox
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function checkbox(?string $name = null, bool|float|int|string|Stringable|null $value = null): Checkbox
{
    $input = Checkbox::tag();
    if ($name !== null) {
        $input = $input->name($name);
    }
    if ($value !== null) {
        $input = $input->value($value);
    }
    return $input;
}

            
class() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::class()

Replace current tag CSS classes with a new set of classes.

public class( \BackedEnum|string|null $class ): Yiisoft\Html\Tag\Input
$class \BackedEnum|string|null

One or many CSS classes.

                final public function class(BackedEnum|string|null ...$class): static
{
    $new = clone $this;
    unset($new->attributes['class']);
    Html::addCssClass($new->attributes, $class);
    return $new;
}

            
color() public static method

Color.

public static color( string|null $name null, string|\Stringable|null $value null ): Yiisoft\Html\Tag\Input\Color
$name string|null

Name of the input.

$value string|\Stringable|null

Value of the input.

                public static function color(?string $name = null, string|Stringable|null $value = null): Color
{
    $input = Color::tag();
    if ($name !== null) {
        $input = $input->name($name);
    }
    if ($value !== null) {
        $input = $input->value($value);
    }
    return $input;
}

            
disabled() public method
public disabled( boolean $disabled true ): Yiisoft\Html\Tag\Input
$disabled boolean

Whether input is disabled.

                public function disabled(bool $disabled = true): static
{
    $new = clone $this;
    $new->attributes['disabled'] = $disabled;
    return $new;
}

            
file() public static method

File input.

public static file( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): Yiisoft\Html\Tag\Input\File
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function file(?string $name = null, bool|float|int|string|Stringable|null $value = null): File
{
    $input = File::tag();
    if ($name !== null) {
        $input = $input->name($name);
    }
    if ($value !== null) {
        $input = $input->value($value);
    }
    return $input;
}

            
form() public method
public form( string|null $formId ): Yiisoft\Html\Tag\Input
$formId string|null

ID of the form input belongs to.

                public function form(?string $formId): static
{
    $new = clone $this;
    $new->attributes['form'] = $formId;
    return $new;
}

            
getName() protected method
protected getName( ): string

                protected function getName(): string
{
    return 'input';
}

            
hidden() public static method

Hidden input.

public static hidden( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): self
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function hidden(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'hidden';
    $input->attributes['name'] = $name;
    $input->attributes['value'] = $value;
    return $input;
}

            
id() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::id()

Set tag ID.

public id( string|null $id ): Yiisoft\Html\Tag\Input
$id string|null

Tag ID.

                final public function id(?string $id): static
{
    $new = clone $this;
    $new->attributes['id'] = $id;
    return $new;
}

            
name() public method
public name( string|null $name ): Yiisoft\Html\Tag\Input
$name string|null

Name of the input.

                public function name(?string $name): static
{
    $new = clone $this;
    $new->attributes['name'] = $name;
    return $new;
}

            
password() public static method

Password input.

public static password( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): self
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function password(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'password';
    $input->attributes['name'] = $name;
    $input->attributes['value'] = $value;
    return $input;
}

            
prepareAttributes() protected method
protected prepareAttributes( ): void

                protected function prepareAttributes(): void {}

            
radio() public static method

Radio input.

public static radio( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): Yiisoft\Html\Tag\Input\Radio
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function radio(?string $name = null, bool|float|int|string|Stringable|null $value = null): Radio
{
    $input = Radio::tag();
    if ($name !== null) {
        $input = $input->name($name);
    }
    if ($value !== null) {
        $input = $input->value($value);
    }
    return $input;
}

            
range() public static method

Range.

public static range( string|null $name null, float|integer|string|\Stringable|null $value null ): Yiisoft\Html\Tag\Input\Range
$name string|null

Name of the input.

$value float|integer|string|\Stringable|null

Value of the input.

                public static function range(?string $name = null, float|int|string|Stringable|null $value = null): Range
{
    $input = Range::tag();
    if ($name !== null) {
        $input = $input->name($name);
    }
    if ($value !== null) {
        $input = $input->value($value);
    }
    return $input;
}

            
readonly() public method
public readonly( boolean $readOnly true ): Yiisoft\Html\Tag\Input
$readOnly boolean

Whether input is read only.

                public function readonly(bool $readOnly = true): static
{
    $new = clone $this;
    $new->attributes['readonly'] = $readOnly;
    return $new;
}

            
removeStyle() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::removeStyle()

Remove CSS styles from the tag.

See also Yiisoft\Html\Html::removeCssStyle().

public removeStyle( string|string[] $properties ): Yiisoft\Html\Tag\Input
$properties string|string[]

The CSS properties to be removed. You may use a string if you are removing a single property.

                final public function removeStyle(string|array $properties): static
{
    $new = clone $this;
    Html::removeCssStyle($new->attributes, $properties);
    return $new;
}

            
render() public method
public render( ): string

                final public function render(): string
{
    return $this->before() . $this->renderTag() . $this->after();
}

            
renderAttributes() protected method

Defined in: Yiisoft\Html\Tag\Base\Tag::renderAttributes()

Render the current tag attributes.

See also Yiisoft\Html\Html::renderTagAttributes().

protected renderAttributes( ): string

                final protected function renderAttributes(): string
{
    $this->prepareAttributes();
    return Html::renderTagAttributes($this->attributes);
}

            
renderTag() protected method
protected renderTag( ): string

                final protected function renderTag(): string
{
    return '<' . $this->getName() . $this->renderAttributes() . '>';
}

            
required() public method
public required( boolean $required true ): Yiisoft\Html\Tag\Input
$required boolean

Whether input is required.

                public function required(bool $required = true): static
{
    $new = clone $this;
    $new->attributes['required'] = $required;
    return $new;
}

            
resetButton() public static method

Reset button.

public static resetButton( string|null $label null ): self
$label string|null

Button label.

                public static function resetButton(?string $label = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'reset';
    $input->attributes['value'] = $label;
    return $input;
}

            
submitButton() public static method

Submit button.

public static submitButton( string|null $label null ): self
$label string|null

Button label.

                public static function submitButton(?string $label = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'submit';
    $input->attributes['value'] = $label;
    return $input;
}

            
tag() public static method
public static tag( ): Yiisoft\Html\Tag\Input

                final public static function tag(): static
{
    return new static();
}

            
text() public static method

Text input.

public static text( string|null $name null, boolean|float|integer|string|\Stringable|null $value null ): self
$name string|null

Name of the input.

$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public static function text(?string $name = null, bool|float|int|string|Stringable|null $value = null): self
{
    $input = self::tag();
    $input->attributes['type'] = 'text';
    $input->attributes['name'] = $name;
    $input->attributes['value'] = $value;
    return $input;
}

            
type() public method

Input with the type specified.

public type( string|null $type ): self
$type string|null

Type of the input.

                public function type(?string $type): self
{
    $new = clone $this;
    $new->attributes['type'] = $type;
    return $new;
}

            
unionAttributes() public method

Defined in: Yiisoft\Html\Tag\Base\Tag::unionAttributes()

Union attributes with a new set.

public unionAttributes( array $attributes ): Yiisoft\Html\Tag\Input
$attributes array

Name-value set of attributes.

                final public function unionAttributes(array $attributes): static
{
    $new = clone $this;
    $new->attributes += $attributes;
    return $new;
}

            
value() public method
public value( boolean|float|integer|string|\Stringable|null $value ): Yiisoft\Html\Tag\Input
$value boolean|float|integer|string|\Stringable|null

Value of the input.

                public function value(bool|float|int|string|Stringable|null $value): static
{
    $new = clone $this;
    $new->attributes['value'] = $value;
    return $new;
}