Skip to content
PHP Ecosystem
Explore

ActiveForm

API reference › Bootstrap 6 › ActiveForm

Renders a Bootstrap 6 form with default, horizontal, inline, or floating-label field layouts.

The layout selects the default ActiveField configuration; override it per form through $fieldConfig. The inline layout adds row lg:row-cols-auto g-3 align-items-center to the form, and $nativeValidation opts the form in to the Bootstrap :user-invalid styling with the data-bs-validate attribute.

See also: https://getbootstrap.com/docs/6.0/forms/layout/, https://getbootstrap.com/docs/6.0/forms/validation/.

PropertyTypeDescriptionDefined by
$actionarray|stringThe form action URL. Default: ''.yii\widgets\ActiveForm
$ajaxDataTypestringThe type of data that you’re expecting back from the server. Default: 'json'.yii\widgets\ActiveForm
$ajaxParamstringThe name of the GET parameter indicating the validation request is an AJAX request. Default: 'ajax'.yii\widgets\ActiveForm
$autoIdPrefix staticstringThe prefix to the automatically generated widget IDs. Default: 'w'.yii\base\Widget
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$clientScriptarray|yii\web\client\ClientScriptInterface|nullClient script class to use for client-side validation. Default: null.yii\widgets\ActiveForm
$enableAjaxValidationboolWhether to enable AJAX-based data validation. Default: false.yii\widgets\ActiveForm
$enableClientScriptboolWhether to hook up yii.activeForm JavaScript plugin. Default: true.yii\widgets\ActiveForm
$enableClientValidationboolWhether to enable client-side data validation. Default: true.yii\widgets\ActiveForm
$encodeErrorSummaryboolWhether to perform encoding on the error summary. Default: true.yii\widgets\ActiveForm
$errorCssClassstringCSS class added to the control when the attribute has validation errors. Default: 'is-invalid'.ActiveForm
$errorSummaryCssClassstringCSS class of the error summary container. Default: 'alert theme-danger'.ActiveForm
$fieldClassstringField class used by field(); it must extend ActiveField. Default: \yii2\extensions\bootstrap6\ActiveField::class.ActiveForm
$fieldConfigarray|ClosureThe default configuration used by field() when creating a new field object. Default: [].yii\widgets\ActiveForm
$idstringId of the widget.yii\base\Widget
$layoutstringForm layout, one of the LAYOUT_* constants. Default: self::LAYOUT_DEFAULT.ActiveForm
$methodstringThe form submission method. Default: 'post'.yii\widgets\ActiveForm
$nativeValidationbool|string|nullClient-side validation styling: true renders data-bs-validate, 'valid' renders data-bs-validate="valid" (success styling too), false removes the attribute, and null keeps $options unchanged. Default: null.ActiveForm
$optionsarrayThe HTML attributes (name-value pairs) for the form tag. Default: [].yii\widgets\ActiveForm
$requiredCssClassstringThe CSS class that is added to a field container when the associated attribute is required. Default: 'required'.yii\widgets\ActiveForm
$scrollToErrorboolWhether to scroll to the first error after validation. Default: true. Available since 2.0.6.yii\widgets\ActiveForm
$scrollToErrorOffsetintOffset in pixels that should be added when scrolling to the first error. Default: 0. Available since 2.0.11.yii\widgets\ActiveForm
$successCssClassstringCSS class added to the control when the attribute passes validation. Default: 'is-valid'.ActiveForm
$validateOnBlurboolWhether to perform validation when an input field loses focus. Default: true.yii\widgets\ActiveForm
$validateOnChangeboolWhether to perform validation when the value of an input field is changed. Default: true.yii\widgets\ActiveForm
$validateOnSubmitboolWhether to perform validation when the form is submitted. Default: true.yii\widgets\ActiveForm
$validateOnTypeboolWhether to perform validation while the user is typing in an input field. Default: false.yii\widgets\ActiveForm
$validatingCssClassstringThe CSS class that is added to a field container when the associated attribute is being validated. Default: 'validating'.yii\widgets\ActiveForm
$validationDelayintNumber of milliseconds that the validation should be delayed when the user types in the field and $validateOnType is set true. Default: 500.yii\widgets\ActiveForm
$validationStateOnstringElement that receives the validation CSS classes; Bootstrap styles the control itself. Default: self::VALIDATION_STATE_ON_INPUT.ActiveForm
$validationUrlarray|string|nullThe URL for performing AJAX-based validation. Default: null.yii\widgets\ActiveForm
$viewyii\web\ViewThe view object that can be used to render views or view files.yii\base\Widget
$viewPath read-onlystringThe directory containing the view files for this widget.yii\base\Widget
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
afterRun()This method is invoked right after a widget is executed.yii\base\Widget
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
beforeRun()This method is invoked right before the widget is executed.yii\base\Widget
begin() staticBegins a widget.yii\base\Widget
beginField()Begins a form field.yii\widgets\ActiveForm
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
end() staticEnds a widget.yii\base\Widget
endField()Ends a form field.yii\widgets\ActiveForm
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
errorSummary()Generates a summary of the validation errors.yii\widgets\ActiveForm
field()ActiveForm
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getId()Returns the ID of the widget.yii\base\Widget
getView()Returns the view object that can be used to render views or view files.yii\base\Widget
getViewPath()Returns the directory containing the view files for this widget.yii\base\Widget
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()ActiveForm
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
registerClientScript()This registers the necessary JavaScript code.yii\widgets\ActiveForm
render()Renders a view.yii\base\Widget
renderFile()Renders a view file.yii\base\Widget
run()Runs the widget.yii\widgets\ActiveForm
setId()Sets the ID of the widget.yii\base\Widget
setView()Sets the view object to be used by this widget.yii\base\Widget
trigger()Triggers an event.yii\base\Component
validate() staticValidates one or several models and returns an error message array indexed by the attribute IDs.yii\widgets\ActiveForm
validateMultiple() staticValidates an array of model instances and returns an error message array indexed by the attribute IDs.yii\widgets\ActiveForm
widget() staticCreates a widget instance and runs it.yii\base\Widget
getClientOptions() protectedyii\widgets\ActiveForm
EventTypeDescriptionDefined by
EVENT_INITyii\base\EventAn event that is triggered when the widget is initialized via init(). Event name: 'init'. Available since 2.0.11.yii\base\Widget
EVENT_BEFORE_RUNyii\base\WidgetEventAn event raised right before executing a widget. Event name: 'beforeRun'. Available since 2.0.11.yii\base\Widget
EVENT_AFTER_RUNyii\base\WidgetEventAn event raised right after executing a widget. Event name: 'afterRun'. Available since 2.0.11.yii\base\Widget
ConstantValueDescriptionDefined by
LAYOUT_DEFAULT'default'Stacked labels, controls, hints, and feedback.ActiveForm
LAYOUT_FLOATING'floating'Floating labels rendered inside a .form-floating wrapper.ActiveForm
LAYOUT_HORIZONTAL'horizontal'Grid rows with the label and the control side by side.ActiveForm
LAYOUT_INLINE'inline'Auto-sized columns with visually hidden labels and no error feedback.ActiveForm
LAYOUTS[self::LAYOUT_DEFAULT, self::LAYOUT_HORIZONTAL, self::LAYOUT_INLINE, self::LAYOUT_FLOATING]Supported layouts.ActiveForm
VALIDATION_STATE_ON_CONTAINER'container'Add validation state class to container tag Available since 2.0.14.yii\widgets\ActiveForm
VALIDATION_STATE_ON_INPUT'input'Add validation state class to input tag Available since 2.0.14.yii\widgets\ActiveForm
public function field(yii\base\Model $model, string $attribute, mixed[] $options = []): yii2\extensions\bootstrap6\ActiveField

Parameters

ParameterTypeDescription
$modelyii\base\ModelModel holding the attribute.
$attributestringAttribute name or expression.
$optionsmixed[]Field configuration merged over $fieldConfig.

Returns

ActiveField

Throws

public function init(): void