# ActiveForm

> ActiveForm is a widget that builds an interactive HTML form for one or multiple data models.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [widgets](/docs/api/yii/widgets/index.md) › ActiveForm

| class | `yii\widgets\ActiveForm` |
| --- | --- |
| Extends | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/widgets/ActiveForm.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/widgets/ActiveForm.php#L27) |

1 subclass:

- [`yii2\extensions\bootstrap6\ActiveForm`](/docs/extensions/bootstrap6/reference/activeform/index.md)

ActiveForm is a widget that builds an interactive HTML form for one or multiple data models.

For more details and usage information on ActiveForm, see the [guide article on forms](/docs/guide/input-forms/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$action`](#property-action) | `array\|string` | The form action URL. Default: `''`. | `ActiveForm` |
| <span id="property-ajaxDataType"></span>`$ajaxDataType` | `string` | The type of data that you're expecting back from the server. Default: `'json'`. | `ActiveForm` |
| <span id="property-ajaxParam"></span>`$ajaxParam` | `string` | The name of the GET parameter indicating the validation request is an AJAX request. Default: `'ajax'`. | `ActiveForm` |
| <span id="property-autoIdPrefix"></span>[`$autoIdPrefix`](/docs/api/yii/base/widget/index.md#property-autoIdPrefix) static | `string` | The prefix to the automatically generated widget IDs. Default: `'w'`. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-clientScript"></span>`$clientScript` | `array\|`[`yii\web\client\ClientScriptInterface`](/docs/api/yii/web/client/clientscriptinterface/index.md)`\|null` | Client script class to use for client-side validation. Default: `null`. | `ActiveForm` |
| [`$enableAjaxValidation`](#property-enableAjaxValidation) | `bool` | Whether to enable AJAX-based data validation. Default: `false`. | `ActiveForm` |
| [`$enableClientScript`](#property-enableClientScript) | `bool` | Whether to hook up `yii.activeForm` JavaScript plugin. Default: `true`. | `ActiveForm` |
| [`$enableClientValidation`](#property-enableClientValidation) | `bool` | Whether to enable client-side data validation. Default: `true`. | `ActiveForm` |
| <span id="property-encodeErrorSummary"></span>`$encodeErrorSummary` | `bool` | Whether to perform encoding on the error summary. Default: `true`. | `ActiveForm` |
| <span id="property-errorCssClass"></span>`$errorCssClass` | `string` | The CSS class that is added to a field container when the associated attribute has validation error. Default: `''`. | `ActiveForm` |
| <span id="property-errorSummaryCssClass"></span>`$errorSummaryCssClass` | `string` | The default CSS class for the error summary container. Default: `'error-summary'`. | `ActiveForm` |
| <span id="property-fieldClass"></span>`$fieldClass` | `string` | The default field class name when calling [`field()`](/docs/api/yii/widgets/activeform/index.md#method-field) to create a new field. Default: `'yii\widgets\ActiveField'`. | `ActiveForm` |
| [`$fieldConfig`](#property-fieldConfig) | `array\|`[`Closure`](https://www.php.net/manual/en/class.closure.php) | The default configuration used by [`field()`](/docs/api/yii/widgets/activeform/index.md#method-field) when creating a new field object. Default: `[]`. | `ActiveForm` |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/widget/index.md#property-id) | `string` | Id of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`$method`](#property-method) | `string` | The form submission method. Default: `'post'`. | `ActiveForm` |
| <span id="property-options"></span>`$options` | `array` | The HTML attributes (name-value pairs) for the form tag. Default: `[]`. | `ActiveForm` |
| <span id="property-requiredCssClass"></span>`$requiredCssClass` | `string` | The CSS class that is added to a field container when the associated attribute is required. Default: `'required'`. | `ActiveForm` |
| <span id="property-scrollToError"></span>`$scrollToError` | `bool` | Whether to scroll to the first error after validation. Default: `true`. Available since 2.0.6. | `ActiveForm` |
| <span id="property-scrollToErrorOffset"></span>`$scrollToErrorOffset` | `int` | Offset in pixels that should be added when scrolling to the first error. Default: `0`. Available since 2.0.11. | `ActiveForm` |
| <span id="property-successCssClass"></span>`$successCssClass` | `string` | The CSS class that is added to a field container when the associated attribute is successfully validated. Default: `''`. | `ActiveForm` |
| [`$validateOnBlur`](#property-validateOnBlur) | `bool` | Whether to perform validation when an input field loses focus. Default: `true`. | `ActiveForm` |
| [`$validateOnChange`](#property-validateOnChange) | `bool` | Whether to perform validation when the value of an input field is changed. Default: `true`. | `ActiveForm` |
| <span id="property-validateOnSubmit"></span>`$validateOnSubmit` | `bool` | Whether to perform validation when the form is submitted. Default: `true`. | `ActiveForm` |
| [`$validateOnType`](#property-validateOnType) | `bool` | Whether to perform validation while the user is typing in an input field. Default: `false`. | `ActiveForm` |
| <span id="property-validatingCssClass"></span>`$validatingCssClass` | `string` | The CSS class that is added to a field container when the associated attribute is being validated. Default: `'validating'`. | `ActiveForm` |
| [`$validationDelay`](#property-validationDelay) | `int` | Number of milliseconds that the validation should be delayed when the user types in the field and [`$validateOnType`](/docs/api/yii/widgets/activeform/index.md#property-validateOnType) is set `true`. Default: `500`. | `ActiveForm` |
| [`$validationStateOn`](#property-validationStateOn) | `string` | Where to render validation state class Could be either "container" or "input". Default: `self::VALIDATION_STATE_ON_CONTAINER`. Available since 2.0.14. | `ActiveForm` |
| [`$validationUrl`](#property-validationUrl) | `array\|string\|null` | The URL for performing AJAX-based validation. Default: `null`. | `ActiveForm` |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/widget/index.md#property-view) | [`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/widget/index.md#property-viewPath) read-only | `string` | The directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-afterRun"></span>[`afterRun()`](/docs/api/yii/base/widget/index.md#method-afterRun) | This method is invoked right after a widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-beforeRun"></span>[`beforeRun()`](/docs/api/yii/base/widget/index.md#method-beforeRun) | This method is invoked right before the widget is executed. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-begin"></span>[`begin()`](/docs/api/yii/base/widget/index.md#method-begin) static | Begins a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`beginField()`](#method-beginField) | Begins a form field. | `ActiveForm` |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-end"></span>[`end()`](/docs/api/yii/base/widget/index.md#method-end) static | Ends a widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`endField()`](#method-endField) | Ends a form field. | `ActiveForm` |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`errorSummary()`](#method-errorSummary) | Generates a summary of the validation errors. | `ActiveForm` |
| [`field()`](#method-field) | Generates a form field. | `ActiveForm` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getId"></span>[`getId()`](/docs/api/yii/base/widget/index.md#method-getId) | Returns the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/widget/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/widget/index.md#method-getViewPath) | Returns the directory containing the view files for this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the widget. | `ActiveForm` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`registerClientScript()`](#method-registerClientScript) | This registers the necessary JavaScript code. | `ActiveForm` |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/widget/index.md#method-render) | Renders a view. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/widget/index.md#method-renderFile) | Renders a view file. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`run()`](#method-run) | Runs the widget. | `ActiveForm` |
| <span id="method-setId"></span>[`setId()`](/docs/api/yii/base/widget/index.md#method-setId) | Sets the ID of the widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/widget/index.md#method-setView) | Sets the view object to be used by this widget. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`validate()`](#method-validate) static | Validates one or several models and returns an error message array indexed by the attribute IDs. | `ActiveForm` |
| [`validateMultiple()`](#method-validateMultiple) static | Validates an array of model instances and returns an error message array indexed by the attribute IDs. | `ActiveForm` |
| <span id="method-widget"></span>[`widget()`](/docs/api/yii/base/widget/index.md#method-widget) static | Creates a widget instance and runs it. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| [`getClientOptions()`](#method-getClientOptions) protected |  | `ActiveForm` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_INIT"></span>[`EVENT_INIT`](/docs/api/yii/base/widget/index.md#event-EVENT_INIT) | [`yii\base\Event`](/docs/api/yii/base/event/index.md) | An event that is triggered when the widget is initialized via [`init()`](/docs/api/yii/base/widget/index.md#method-init). Event name: `'init'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_BEFORE_RUN"></span>[`EVENT_BEFORE_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_BEFORE_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right before executing a widget. Event name: `'beforeRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |
| <span id="event-EVENT_AFTER_RUN"></span>[`EVENT_AFTER_RUN`](/docs/api/yii/base/widget/index.md#event-EVENT_AFTER_RUN) | [`yii\base\WidgetEvent`](/docs/api/yii/base/widgetevent/index.md) | An event raised right after executing a widget. Event name: `'afterRun'`. Available since 2.0.11. | [`yii\base\Widget`](/docs/api/yii/base/widget/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-VALIDATION_STATE_ON_CONTAINER"></span>`VALIDATION_STATE_ON_CONTAINER` | `'container'` | Add validation state class to container tag Available since 2.0.14. | `ActiveForm` |
| <span id="const-VALIDATION_STATE_ON_INPUT"></span>`VALIDATION_STATE_ON_INPUT` | `'input'` | Add validation state class to input tag Available since 2.0.14. | `ActiveForm` |

## Property details

### $action <span id="property-action"></span>

```php
public array|string $action = ''
```

The form action URL.

This parameter will be processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to).

### $enableAjaxValidation <span id="property-enableAjaxValidation"></span>

```php
public bool $enableAjaxValidation = false
```

Whether to enable AJAX-based data validation.

If [`ActiveField::$enableAjaxValidation`](/docs/api/yii/widgets/activefield/index.md#property-enableAjaxValidation) is set, its value will take precedence for that input field.

### $enableClientScript <span id="property-enableClientScript"></span>

```php
public bool $enableClientScript = true
```

Whether to hook up `yii.activeForm` JavaScript plugin.

This property must be set `true` if you want to support client validation and/or AJAX validation, or if you
want to take advantage of the `yii.activeForm` plugin. When this is `false`, the form will not generate
any JavaScript.

### $enableClientValidation <span id="property-enableClientValidation"></span>

```php
public bool $enableClientValidation = true
```

Whether to enable client-side data validation.

If [`ActiveField::$enableClientValidation`](/docs/api/yii/widgets/activefield/index.md#property-enableClientValidation) is set, its value will take precedence for that input field.

### $fieldConfig <span id="property-fieldConfig"></span>

```php
public array|Closure $fieldConfig = []
```

The default configuration used by [`field()`](/docs/api/yii/widgets/activeform/index.md#method-field) when creating a new field object.

This can be either a configuration array or an anonymous function returning a configuration array.
If the latter, the signature should be as follows:

```
function ($model, $attribute)
```

The value of this property will be merged recursively with the `$options` parameter passed to [`field()`](/docs/api/yii/widgets/activeform/index.md#method-field).

### $method <span id="property-method"></span>

```php
public string $method = 'post'
```

The form submission method.

This should be either `post` or `get`. Defaults to `post`.

When you set this to `get` you may see the url parameters repeated on each request.
This is because the default value of [`$action`](/docs/api/yii/widgets/activeform/index.md#property-action) is set to be the current request url and each submit
will add new parameters instead of replacing existing ones.
You may set [`$action`](/docs/api/yii/widgets/activeform/index.md#property-action) explicitly to avoid this:

```
$form = ActiveForm::begin([
    'method' => 'get',
    'action' => ['controller/action'],
]);
```

### $validateOnBlur <span id="property-validateOnBlur"></span>

```php
public bool $validateOnBlur = true
```

Whether to perform validation when an input field loses focus.

If [`ActiveField::$validateOnBlur`](/docs/api/yii/widgets/activefield/index.md#property-validateOnBlur) is set, its value will take precedence for that input field.

### $validateOnChange <span id="property-validateOnChange"></span>

```php
public bool $validateOnChange = true
```

Whether to perform validation when the value of an input field is changed.

If [`ActiveField::$validateOnChange`](/docs/api/yii/widgets/activefield/index.md#property-validateOnChange) is set, its value will take precedence for that input field.

### $validateOnType <span id="property-validateOnType"></span>

```php
public bool $validateOnType = false
```

Whether to perform validation while the user is typing in an input field.

If [`ActiveField::$validateOnType`](/docs/api/yii/widgets/activefield/index.md#property-validateOnType) is set, its value will take precedence for that input field.

### $validationDelay <span id="property-validationDelay"></span>

```php
public int $validationDelay = 500
```

Number of milliseconds that the validation should be delayed when the user types in the field and [`$validateOnType`](/docs/api/yii/widgets/activeform/index.md#property-validateOnType) is set `true`.

If [`ActiveField::$validationDelay`](/docs/api/yii/widgets/activefield/index.md#property-validationDelay) is set, its value will take precedence for that input field.

### $validationStateOn <span id="property-validationStateOn"></span>

```php
public string $validationStateOn = self::VALIDATION_STATE_ON_CONTAINER
```

Where to render validation state class Could be either "container" or "input".

Default is "container".

**Since**

2.0.14

### $validationUrl <span id="property-validationUrl"></span>

```php
public array|string|null $validationUrl = null
```

The URL for performing AJAX-based validation.

This property will be processed by
`Url::to()`. Please refer to `Url::to()` for more details on how to configure this property.
If this property is not set, it will take the value of the form's action attribute.

## Method details

### beginField() <span id="method-beginField"></span>

```php
public function beginField(yii\base\Model $model, string $attribute, array $options = []): string
```

Begins a form field.

This method will create a new form field and returns its opening tag.
You should call [`endField()`](/docs/api/yii/widgets/activeform/index.md#method-endField) afterwards.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The data model. |
| `$attribute` | `string` | The attribute name or expression. See [`Html::getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The additional configurations for the field object. |

**Returns**

`string`: The opening tag.

**See also**

- [`endField()`](/docs/api/yii/widgets/activeform/index.md#method-endField)
- [`field()`](/docs/api/yii/widgets/activeform/index.md#method-field)

### endField() <span id="method-endField"></span>

```php
public function endField(): string
```

Ends a form field.

This method will return the closing tag of an active form field started by [`beginField()`](/docs/api/yii/widgets/activeform/index.md#method-beginField).

**Returns**

`string`: The closing tag of the form field.

**Throws**

- [`yii\base\InvalidCallException`](/docs/api/yii/base/invalidcallexception/index.md): if this method is called without a prior [`beginField()`](/docs/api/yii/widgets/activeform/index.md#method-beginField) call.

### errorSummary() <span id="method-errorSummary"></span>

```php
public function errorSummary(yii\base\Model|yii\base\Model[] $models, array $options = []): string
```

Generates a summary of the validation errors.

If there is no validation error, an empty error summary markup will still be generated, but it will be hidden.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$models` | [`yii\base\Model`](/docs/api/yii/base/model/index.md)`\|`[`yii\base\Model`](/docs/api/yii/base/model/index.md)`[]` | The model(s) associated with this form. |
| `$options` | `array` | The tag options in terms of name-value pairs. The following options are specially handled: - `header`: string, the header HTML for the error summary. If not set, a default prompt string will be used. - `footer`: string, the footer HTML for the error summary. The rest of the options will be rendered as the attributes of the container tag. The values will be HTML-encoded using [`Html::encode()`](/docs/api/yii/helpers/basehtml/index.md#method-encode). If a value is `null`, the corresponding attribute will not be rendered. |

**Returns**

`string`: The generated error summary.

**See also**

- [`$errorSummaryCssClass`](/docs/api/yii/widgets/activeform/index.md#property-errorSummaryCssClass)

### field() <span id="method-field"></span>

```php
public function field(yii\base\Model $model, string $attribute, array $options = []): yii\widgets\ActiveField
```

Generates a form field.

A form field is associated with a model and an attribute. It contains a label, an input and an error message
and use them to interact with end users to collect their inputs for the attribute.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The data model. |
| `$attribute` | `string` | The attribute name or expression. See [`Html::getAttributeName()`](/docs/api/yii/helpers/basehtml/index.md#method-getAttributeName) for the format about attribute expression. |
| `$options` | `array` | The additional configurations for the field object. These are properties of [`ActiveField`](/docs/api/yii/widgets/activefield/index.md) or a subclass, depending on the value of [`$fieldClass`](/docs/api/yii/widgets/activeform/index.md#property-fieldClass). |

**Returns**

[`ActiveField`](/docs/api/yii/widgets/activefield/index.md): The created ActiveField object.

**See also**

- [`$fieldConfig`](/docs/api/yii/widgets/activeform/index.md#property-fieldConfig)

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the widget.

This renders the form open tag.

**Returns**

`mixed`

### registerClientScript() <span id="method-registerClientScript"></span>

```php
public function registerClientScript(): mixed
```

This registers the necessary JavaScript code.

**Returns**

`mixed`

**Since**

2.0.12

### run() <span id="method-run"></span>

```php
public function run(): mixed
```

Runs the widget.

This registers the necessary JavaScript code and renders the form open and close tags.

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidCallException`](/docs/api/yii/base/invalidcallexception/index.md): if `beginField()` and `endField()` calls are not matching.

### validate() <span id="method-validate"></span>

```php
public static function validate(yii\base\Model $model, mixed $attributes = null): array<string, string[]>
```

Validates one or several models and returns an error message array indexed by the attribute IDs.

This is a helper method that simplifies the way of writing AJAX validation code.

For example, you may use the following code in a controller action to respond
to an AJAX validation request:

```
$model = new Post;
$model->load(Yii::$app->request->post());
if (Yii::$app->request->isAjax) {
    Yii::$app->response->format = Response::FORMAT_JSON;
    return ActiveForm::validate($model);
}
// ... respond to non-AJAX request ...
```

To validate multiple models, simply pass each model as a parameter to this method, like
the following:

```
ActiveForm::validate($model1, $model2, ...);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$model` | [`yii\base\Model`](/docs/api/yii/base/model/index.md) | The model to be validated. |
| `$attributes` | `mixed` | List of attributes that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated. When this method is used to validate multiple models, this parameter will be interpreted as a model. |

**Returns**

`array<string, string[]>`: The error message array indexed by the attribute IDs.

### validateMultiple() <span id="method-validateMultiple"></span>

```php
public static function validateMultiple(array $models, mixed $attributes = null): array
```

Validates an array of model instances and returns an error message array indexed by the attribute IDs.

This is a helper method that simplifies the way of writing AJAX validation code for tabular input.

For example, you may use the following code in a controller action to respond
to an AJAX validation request:

```
// ... load $models ...
if (Yii::$app->request->isAjax) {
    Yii::$app->response->format = Response::FORMAT_JSON;
    return ActiveForm::validateMultiple($models);
}
// ... respond to non-AJAX request ...
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$models` | `array` | An array of models to be validated. |
| `$attributes` | `mixed` | List of attributes that should be validated. If this parameter is empty, it means any attribute listed in the applicable validation rules should be validated. |

**Returns**

`array`: The error message array indexed by the attribute IDs.

### getClientOptions() <span id="method-getClientOptions"></span>

```php
protected function getClientOptions(): mixed
```

**Returns**

`mixed`