0 follower

Class Yiisoft\FormModel\Field

InheritanceYiisoft\FormModel\Field

Field is a shortcut static factory to ease creation of fields of various builtin types.

Public Methods

Hide inherited methods

Method Description Defined By
button() Create a button field. Yiisoft\FormModel\Field
buttonGroup() Create a button group field. Yiisoft\FormModel\Field
checkbox() Create a checkbox field. Yiisoft\FormModel\Field
checkboxList() Create checkboxes list field. Yiisoft\FormModel\Field
date() Create a date field. Yiisoft\FormModel\Field
dateTimeLocal() Create a local date and time field. Yiisoft\FormModel\Field
email() Create an email field. Yiisoft\FormModel\Field
error() Create an error for a field. Yiisoft\FormModel\Field
errorSummary() Create errors summary field. Yiisoft\FormModel\Field
fieldset() Create a fieldset. Yiisoft\FormModel\Field
file() Create a file upload field. Yiisoft\FormModel\Field
hidden() Create a hidden field. Yiisoft\FormModel\Field
hint() Create a field hint. Yiisoft\FormModel\Field
image() Create an image. Yiisoft\FormModel\Field
label() Create a field label. Yiisoft\FormModel\Field
number() Create a number field. Yiisoft\FormModel\Field
password() Create a password field. Yiisoft\FormModel\Field
radioList() Create a radio list field. Yiisoft\FormModel\Field
range() Create a range field. Yiisoft\FormModel\Field
resetButton() Create a reset button. Yiisoft\FormModel\Field
select() Create a select field. Yiisoft\FormModel\Field
submitButton() Create a submit button. Yiisoft\FormModel\Field
telephone() Create a phone number field. Yiisoft\FormModel\Field
text() Create a text field. Yiisoft\FormModel\Field
textarea() Create a text area field. Yiisoft\FormModel\Field
time() Create a time field. Yiisoft\FormModel\Field
url() Create a URL input field. Yiisoft\FormModel\Field

Constants

Hide inherited constants

Constant Value Description Defined By
DEFAULT_THEME null Yiisoft\FormModel\Field

Method Details

Hide inherited methods

button() public static method

Create a button field.

public static \Yiisoft\Form\Field\Button button ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function button(?string $content = null, array $config = [], ?string $theme = null): Button
{
    $field = Button::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
buttonGroup() public static method

Create a button group field.

public static \Yiisoft\Form\Field\ButtonGroup buttonGroup ( array $config = [], string|null $theme null )
$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function buttonGroup(array $config = [], ?string $theme = null): ButtonGroup
{
    return ButtonGroup::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
}

            
checkbox() public static method

Create a checkbox field.

public static \Yiisoft\Form\Field\Checkbox checkbox ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function checkbox(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Checkbox {
    return Checkbox::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
checkboxList() public static method

Create checkboxes list field.

public static \Yiisoft\Form\Field\CheckboxList checkboxList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function checkboxList(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): CheckboxList {
    return CheckboxList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
date() public static method

Create a date field.

public static \Yiisoft\Form\Field\Date date ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function date(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Date {
    return Date::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
dateTimeLocal() public static method

Create a local date and time field.

public static \Yiisoft\Form\Field\DateTimeLocal dateTimeLocal ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function dateTimeLocal(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): DateTimeLocal {
    return DateTimeLocal::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
email() public static method

Create an email field.

public static \Yiisoft\Form\Field\Email email ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function email(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Email {
    return Email::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
error() public static method

Create an error for a field.

public static \Yiisoft\Form\Field\Part\Error error ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create error for.

$property string

Model property name to create error for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function error(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Error {
    return Error::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
errorSummary() public static method

Create errors summary field.

public static \Yiisoft\Form\Field\ErrorSummary errorSummary ( Yiisoft\FormModel\FormModelInterface|null $formModel null, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface|null

Model to take errors from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function errorSummary(
    ?FormModelInterface $formModel = null,
    array $config = [],
    ?string $theme = null,
): ErrorSummary {
    $widget = ErrorSummary::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
    if ($formModel !== null) {
        $widget = $widget->errors(
            $formModel->isValidated()
                ? $formModel->getValidationResult()->getErrorMessagesIndexedByProperty()
                : []
        );
    }
    return $widget;
}

            
fieldset() public static method

Create a fieldset.

public static \Yiisoft\Form\Field\Fieldset fieldset ( array $config = [], string|null $theme null )
$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function fieldset(array $config = [], ?string $theme = null): Fieldset
{
    return Fieldset::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
}

            
file() public static method

Create a file upload field.

public static \Yiisoft\Form\Field\File file ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function file(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): File {
    return File::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
hidden() public static method

Create a hidden field.

public static \Yiisoft\Form\Field\Hidden hidden ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function hidden(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Hidden {
    return Hidden::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
hint() public static method

Create a field hint.

public static \Yiisoft\Form\Field\Part\Hint hint ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create hint for.

$property string

Model property name to create hint for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function hint(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Hint {
    return Hint::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
image() public static method

Create an image.

public static \Yiisoft\Form\Field\Image image ( string|null $url null, array $config = [], string|null $theme null )
$url string|null

"src" of the image.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function image(?string $url = null, array $config = [], ?string $theme = null): Image
{
    $field = Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
    if ($url !== null) {
        $field = $field->src($url);
    }
    return $field;
}

            
label() public static method

Create a field label.

public static \Yiisoft\Form\Field\Part\Label label ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to create label for.

$property string

Model property name to create label for.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function label(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Label {
    return Label::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
number() public static method

Create a number field.

public static \Yiisoft\Form\Field\Number number ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function number(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Number {
    return Number::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
password() public static method

Create a password field.

public static \Yiisoft\Form\Field\Password password ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function password(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Password {
    return Password::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
radioList() public static method

Create a radio list field.

public static \Yiisoft\Form\Field\RadioList radioList ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function radioList(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): RadioList {
    return RadioList::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
range() public static method

Create a range field.

public static \Yiisoft\Form\Field\Range range ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function range(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Range {
    return Range::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
resetButton() public static method

Create a reset button.

public static \Yiisoft\Form\Field\ResetButton resetButton ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function resetButton(
    ?string $content = null,
    array $config = [],
    ?string $theme = null,
): ResetButton {
    $field = ResetButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
select() public static method

Create a select field.

public static \Yiisoft\Form\Field\Select select ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function select(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Select {
    return Select::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
submitButton() public static method

Create a submit button.

public static \Yiisoft\Form\Field\SubmitButton submitButton ( string|null $content null, array $config = [], string|null $theme null )
$content string|null

Button content.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function submitButton(
    ?string $content = null,
    array $config = [],
    ?string $theme = null,
): SubmitButton {
    $field = SubmitButton::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
    if ($content !== null) {
        $field = $field->content($content);
    }
    return $field;
}

            
telephone() public static method

Create a phone number field.

public static \Yiisoft\Form\Field\Telephone telephone ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function telephone(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Telephone {
    return Telephone::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
text() public static method

Create a text field.

public static \Yiisoft\Form\Field\Text text ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function text(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Text {
    return Text::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
textarea() public static method

Create a text area field.

public static \Yiisoft\Form\Field\Textarea textarea ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function textarea(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Textarea {
    return Textarea::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
time() public static method

Create a time field.

public static \Yiisoft\Form\Field\Time time ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function time(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Time {
    return Time::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}

            
url() public static method

Create a URL input field.

public static \Yiisoft\Form\Field\Url url ( Yiisoft\FormModel\FormModelInterface $formModel, string $property, array $config = [], string|null $theme null )
$formModel Yiisoft\FormModel\FormModelInterface

Model to take value from.

$property string

Model property name to take value from.

$config array

Widget config.

$theme string|null

Theme to use. If not specified, default theme is used.

                final public static function url(
    FormModelInterface $formModel,
    string $property,
    array $config = [],
    ?string $theme = null,
): Url {
    return Url::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME)
        ->inputData(new FormModelInputData($formModel, $property));
}