0 follower

Final Class Yiisoft\Html\Tag\Form

InheritanceYiisoft\Html\Tag\Form » Yiisoft\Html\Tag\Base\NormalTag » Yiisoft\Html\Tag\Base\Tag
ImplementsYiisoft\Html\NoEncodeStringableInterface
Uses TraitsYiisoft\Html\Tag\Base\TagContentTrait

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
acceptCharset() Character encodings to use for form submission. Yiisoft\Html\Tag\Form
action() The URL to use for form submission. Yiisoft\Html\Tag\Form
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
addContent() Yiisoft\Html\Tag\Base\TagContentTrait
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
autocomplete() Default setting for autofill feature for controls in the form. Yiisoft\Html\Tag\Form
class() Replace current tag CSS classes with a new set of classes. Yiisoft\Html\Tag\Base\Tag
close() Yiisoft\Html\Tag\Base\NormalTag
content() Yiisoft\Html\Tag\Base\TagContentTrait
csrf() Yiisoft\Html\Tag\Form
doubleEncode() Yiisoft\Html\Tag\Base\TagContentTrait
encode() Yiisoft\Html\Tag\Base\TagContentTrait
enctype() Entry list encoding type to use for form submission. Yiisoft\Html\Tag\Form
enctypeApplicationXWwwFormUrlencoded() All characters are encoded before sending. Yiisoft\Html\Tag\Form
enctypeMultipartFormData() The type that allows file <input> element(s) to upload file data. Yiisoft\Html\Tag\Form
enctypeTextPlain() Sends data without any encoding at all. Not recommended. Yiisoft\Html\Tag\Form
get() Yiisoft\Html\Tag\Form
id() Set tag ID. Yiisoft\Html\Tag\Base\Tag
method() The method content attribute specifies how the form-data should be submitted. Yiisoft\Html\Tag\Form
noValidate() A boolean attribute, which, if present, indicate that the form is not to be validated during submission. Yiisoft\Html\Tag\Form
open() Yiisoft\Html\Tag\Base\NormalTag
post() Yiisoft\Html\Tag\Form
removeStyle() Remove CSS styles from the tag. Yiisoft\Html\Tag\Base\Tag
render() Yiisoft\Html\Tag\Base\Tag
tag() Yiisoft\Html\Tag\Base\NormalTag
target() Browsing context for form submission. Yiisoft\Html\Tag\Form
unionAttributes() Union attributes with a new set. Yiisoft\Html\Tag\Base\Tag

Constants

Hide inherited constants

Constant Value Description Defined By
ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED 'application/x-www-form-urlencoded' Yiisoft\Html\Tag\Form
ENCTYPE_MULTIPART_FORM_DATA 'multipart/form-data' Yiisoft\Html\Tag\Form
ENCTYPE_TEXT_PLAIN 'text/plain' Yiisoft\Html\Tag\Form

Method Details

Hide inherited methods

__toString() public method
public __toString( ): string

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

            
acceptCharset() public method

Character encodings to use for form submission.

public acceptCharset( string|null $charset ): self
$charset string|null

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

            
action() public method

The URL to use for form submission.

public action( string|null $url ): self
$url string|null

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

            
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\Form
$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\Form
$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;
}

            
addContent() public method
public addContent( string|\Stringable $content ): Yiisoft\Html\Tag\Form
$content string|\Stringable

Tag content.

                final public function addContent(string|Stringable ...$content): static
{
    $new = clone $this;
    $new->content = array_merge($new->content, array_values($content));
    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\Form
$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\Form
$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\Form
$attributes array

Name-value set of attributes.

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

            
autocomplete() public method

Default setting for autofill feature for controls in the form.

public autocomplete( boolean $value true ): self
$value boolean

                public function autocomplete(bool $value = true): self
{
    $new = clone $this;
    $new->attributes['autocomplete'] = $value ? 'on' : 'off';
    return $new;
}

            
before() protected method
protected before( ): string

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

            
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\Form
$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;
}

            
close() public method
public close( ): string
return string

Closing tag.

                final public function close(): string
{
    return '</' . $this->getName() . '>';
}

            
content() public method
public content( string|\Stringable $content ): Yiisoft\Html\Tag\Form
$content string|\Stringable

Tag content.

                final public function content(string|Stringable ...$content): static
{
    $new = clone $this;
    $new->content = array_values($content);
    return $new;
}

            
csrf() public method

public csrf( string|\Stringable|null $token, string $name '_csrf' ): self
$token string|\Stringable|null
$name string

                public function csrf(string|Stringable|null $token, string $name = '_csrf'): self
{
    $new = clone $this;
    $new->csrfToken = $token === null ? null : (string) $token;
    $new->csrfName = $name;
    return $new;
}

            
doubleEncode() public method
public doubleEncode( boolean $doubleEncode ): Yiisoft\Html\Tag\Form
$doubleEncode boolean

Whether already encoded HTML entities in tag content should be encoded. Defaults to true.

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

            
encode() public method
public encode( boolean|null $encode ): Yiisoft\Html\Tag\Form
$encode boolean|null

Whether to encode tag content. Supported values:

  • null: stringable objects that implement interface Yiisoft\Html\NoEncodeStringableInterface are not encoded, everything else is encoded;
  • true: any content is encoded;
  • false: nothing is encoded. Defaults to null.

                final public function encode(?bool $encode): static
{
    $new = clone $this;
    $new->encode = $encode;
    return $new;
}

            
enctype() public method

Entry list encoding type to use for form submission.

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

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

            
enctypeApplicationXWwwFormUrlencoded() public method

All characters are encoded before sending.

public enctypeApplicationXWwwFormUrlencoded( ): self

                public function enctypeApplicationXWwwFormUrlencoded(): self
{
    return $this->enctype(self::ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED);
}

            
enctypeMultipartFormData() public method

The type that allows file <input> element(s) to upload file data.

public enctypeMultipartFormData( ): self

                public function enctypeMultipartFormData(): self
{
    return $this->enctype(self::ENCTYPE_MULTIPART_FORM_DATA);
}

            
enctypeTextPlain() public method

Sends data without any encoding at all. Not recommended.

public enctypeTextPlain( ): self

                public function enctypeTextPlain(): self
{
    return $this->enctype(self::ENCTYPE_TEXT_PLAIN);
}

            
generateContent() protected abstract method
protected abstract generateContent( ): string

                abstract protected function generateContent(): string;

            
get() public method

public get( string|null $url null ): self
$url string|null

                public function get(?string $url = null): self
{
    $new = clone $this;
    $new->attributes['method'] = 'GET';
    if ($url !== null) {
        $new->attributes['action'] = $url;
    }
    return $new;
}

            
getName() protected method

protected getName( ): string

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

            
id() public method

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

Set tag ID.

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

Tag ID.

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

            
method() public method

The method content attribute specifies how the form-data should be submitted.

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

The method attribute value.

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

            
noValidate() public method

A boolean attribute, which, if present, indicate that the form is not to be validated during submission.

public noValidate( boolean $noValidate true ): self
$noValidate boolean

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

            
open() public method
public open( ): string
return string

Opening tag.

                final public function open(): string
{
    return '<' . $this->getName() . $this->renderAttributes() . '>' . $this->prepend();
}

            
post() public method

public post( string|null $url null ): self
$url string|null

                public function post(?string $url = null): self
{
    $new = clone $this;
    $new->attributes['method'] = 'POST';
    if ($url !== null) {
        $new->attributes['action'] = $url;
    }
    return $new;
}

            
prepareAttributes() protected method
protected prepareAttributes( ): void

                protected function prepareAttributes(): void {}

            
prepend() protected method

protected prepend( ): string

                protected function prepend(): string
{
    return $this->csrfToken !== null
        ? "\n" . Input::hidden($this->csrfName, $this->csrfToken)
        : '';
}

            
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\Form
$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->open() . $this->generateContent() . $this->close();
}

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

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

            
target() public method

Browsing context for form submission.

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

The target attribute value.

                public function target(?string $target): self
{
    $new = clone $this;
    $new->attributes['target'] = $target;
    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\Form
$attributes array

Name-value set of attributes.

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