Class yii\bootstrap\ActiveForm
Inheritance | yii\bootstrap\ActiveForm » yii\widgets\ActiveForm » yii\base\Widget » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable, yii\base\ViewContextInterface |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/bootstrap/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 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 $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:
- yii\bootstrap\ActiveField for details on the $fieldConfig options.
- http://getbootstrap.com/css/#forms
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$action | array|string | The form action URL. | yii\widgets\ActiveForm |
$ajaxDataType | string | The type of data that you're expecting back from the server. | yii\widgets\ActiveForm |
$ajaxParam | string | The name of the GET parameter indicating the validation request is an AJAX request. | yii\widgets\ActiveForm |
$attributes | array | The client validation options for individual attributes. | yii\widgets\ActiveForm |
$autoIdPrefix | string | The prefix to the automatically generated widget IDs. | yii\base\Widget |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. | yii\base\Component |
$counter | integer | A counter used to generate $id for widgets. | yii\base\Widget |
$enableAjaxValidation | boolean | Whether to enable AJAX-based data validation. | yii\widgets\ActiveForm |
$enableClientScript | boolean | Whether to hook up `yii. | yii\widgets\ActiveForm |
$enableClientValidation | boolean | Whether to enable client-side data validation. | yii\widgets\ActiveForm |
$encodeErrorSummary | boolean | Whether to perform encoding on the error summary. | yii\widgets\ActiveForm |
$errorCssClass | string | The CSS class that is added to a field container when the associated attribute has validation error. | yii\widgets\ActiveForm |
$errorSummaryCssClass | string | The default CSS class for the error summary container. | yii\widgets\ActiveForm |
$fieldClass | string | The default field class name when calling field() to create a new field. | yii\bootstrap\ActiveForm |
$fieldConfig | array|Closure | The default configuration used by field() when creating a new field object. | yii\widgets\ActiveForm |
$id | string|null | ID of the widget. Note that the type of this property differs in getter and setter. See getId() and setId() for details. | yii\base\Widget |
$layout | string | The form layout. | yii\bootstrap\ActiveForm |
$method | string | The form submission method. | yii\widgets\ActiveForm |
$options | array | HTML attributes for the form tag. | yii\bootstrap\ActiveForm |
$requiredCssClass | string | The CSS class that is added to a field container when the associated attribute is required. | yii\widgets\ActiveForm |
$scrollToError | boolean | Whether to scroll to the first error after validation. | yii\widgets\ActiveForm |
$scrollToErrorOffset | integer | Offset in pixels that should be added when scrolling to the first error. | yii\widgets\ActiveForm |
$stack | yii\base\Widget[] | The widgets that are currently being rendered (not ended). | yii\base\Widget |
$successCssClass | string | The CSS class that is added to a field container when the associated attribute is successfully validated. | yii\widgets\ActiveForm |
$validateOnBlur | boolean | Whether to perform validation when an input field loses focus. | yii\widgets\ActiveForm |
$validateOnChange | boolean | Whether to perform validation when the value of an input field is changed. | yii\widgets\ActiveForm |
$validateOnSubmit | boolean | Whether to perform validation when the form is submitted. | yii\widgets\ActiveForm |
$validateOnType | boolean | Whether to perform validation while the user is typing in an input field. | yii\widgets\ActiveForm |
$validatingCssClass | string | The CSS class that is added to a field container when the associated attribute is being validated. | yii\widgets\ActiveForm |
$validationDelay | integer | Number of milliseconds that the validation should be delayed when the user types in the field
and $validateOnType is set true . |
yii\widgets\ActiveForm |
$validationStateOn | string | Where to render validation state class Could be either "container" or "input". | yii\widgets\ActiveForm |
$validationUrl | array|string|null | The URL for performing AJAX-based validation. | yii\widgets\ActiveForm |
$view | yii\web\View | The view object that can be used to render views or view files. Note that the type of this property differs in getter and setter. See getView() and setView() for details. | yii\base\Widget |
$viewPath | string | The directory containing the view files for this widget. | yii\base\Widget |
Public Methods
Method | Description | Defined By |
---|---|---|
__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 |
__construct() | Constructor. | yii\base\BaseObject |
__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() | Begins 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() | Returns 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() | Ends 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() | Generates a form field. | yii\bootstrap\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() | Initializes the widget. | yii\bootstrap\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() | Validates one or several models and returns an error message array indexed by the attribute IDs. | yii\widgets\ActiveForm |
validateMultiple() | Validates an array of model instances and returns an error message array indexed by the attribute IDs. | yii\widgets\ActiveForm |
widget() | Creates a widget instance and runs it. | yii\base\Widget |
Protected Methods
Method | Description | Defined By |
---|---|---|
getClientOptions() | Returns the options for the form JS widget. | yii\widgets\ActiveForm |
Events
Event | Type | Description | Defined By |
---|---|---|---|
EVENT_AFTER_RUN | yii\base\WidgetEvent | An event raised right after executing a widget. (available since version 2.0.11) | yii\base\Widget |
EVENT_BEFORE_RUN | yii\base\WidgetEvent | An event raised right before executing a widget. (available since version 2.0.11) | yii\base\Widget |
EVENT_INIT | yii\base\Event | An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) | yii\base\Widget |
Constants
Constant | Value | Description | Defined By |
---|---|---|---|
VALIDATION_STATE_ON_CONTAINER | 'container' | Add validation state class to container tag | yii\widgets\ActiveForm |
VALIDATION_STATE_ON_INPUT | 'input' | Add validation state class to input tag | yii\widgets\ActiveForm |
Property Details
The default field class name when calling field() to create a new field.
See also $fieldConfig.
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 $fieldConfig.
See also yii\bootstrap\ActiveField for details on Bootstrap 3 field configuration.
HTML attributes for the form tag. Default is []
.
Method Details
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.
public yii\bootstrap\ActiveField field ( $model, $attribute, $options = [] ) | ||
$model | yii\base\Model | The data model. |
$attribute | string | The attribute name or expression. See yii\bootstrap\Html::getAttributeName() for the format about attribute expression. |
$options | array | The additional configurations for the field object. These are properties of yii\bootstrap\ActiveField or a subclass, depending on the value of $fieldClass. |
return | yii\bootstrap\ActiveField | The created ActiveField object |
---|
Initializes the widget.
This renders the form open tag.
public void init ( ) |