Class yii\bootstrap\ActiveForm

Inheritanceyii\bootstrap\ActiveForm » yii\widgets\ActiveForm
Available since version2.0
Source Code https://github.com/yiisoft/yii2-bootstrap/blob/master/ActiveForm.php

A Bootstrap 3 enhanced version of \yii\widgets\ActiveForm.

This class mainly adds the $layout property to choose a Bootstrap 3 form layout. So for example to render a horizontal form you would:

use yii\bootstrap\ActiveForm;

$form = ActiveForm::begin(['layout' => 'horizontal'])

This will set default values for the yii\bootstrap\ActiveField to render horizontal form fields. In particular the yii\bootstrap\ActiveField::template is set to {label} {beginWrapper} {input} {error} {endWrapper} {hint} and the horizontalCssClasses are set to:

[
    'offset' => 'col-sm-offset-3',
    'label' => 'col-sm-3',
    'wrapper' => 'col-sm-6',
    'error' => '',
    'hint' => 'col-sm-3',
]

To get a different column layout in horizontal mode you can modify those options through \yii\bootstrap\fieldConfig:

$form = ActiveForm::begin([
    'layout' => 'horizontal',
    'fieldConfig' => [
        'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
        'horizontalCssClasses' => [
            'label' => 'col-sm-4',
            'offset' => 'col-sm-offset-4',
            'wrapper' => 'col-sm-8',
            'error' => '',
            'hint' => '',
        ],
    ],
]);

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$fieldClass string The default field class name when calling field() to create a new field. yii\bootstrap\ActiveForm
$layout string The form layout. yii\bootstrap\ActiveForm
$options array HTML attributes for the form tag. yii\bootstrap\ActiveForm

Property Details

$fieldClass public property

The default field class name when calling field() to create a new field.

See also \yii\bootstrap\fieldConfig.

public string $fieldClass 'yii\bootstrap\ActiveField'
$layout public property

The form layout. Either 'default', 'horizontal' or 'inline'. By choosing a layout, an appropriate default field configuration is applied. This will render the form fields with slightly different markup for each layout. You can override these defaults through \yii\bootstrap\fieldConfig.

See also yii\bootstrap\ActiveField for details on Bootstrap 3 field configuration.

public string $layout 'default'
$options public property

HTML attributes for the form tag. Default is [].

public array $options = []

Method Details

field() public method

public yii\bootstrap\ActiveField field ( $model, $attribute, $options = [] )
$model
$attribute
$options
return yii\bootstrap\ActiveField

The created ActiveField object

init() public method

public void init ( )