PHP Class kartik\builder\BaseForm

Since: 1.0
Author: Kartik Visweswaran ([email protected])
Inheritance: extends yii\bootstrap\Widget, use trait FormTrait
Show file Open project: kartik-v/yii2-builder Class Usage Examples

Public Properties

Property Type Description
$attributeDefaults the default settings that will be applied for all attributes. The array will be configured similar to a single attribute setting value in the $attributes array. One will typically default markup and styling like type, container, prepend, append etc. The settings at the $attributes level will override these default settings.
$attributes the attribute settings. This is an associative array, which needs to be setup as $attribute_name => $attribute_settings, where: - attribute_name: _string_, the name of the attribute - attribute_settings: _array_, the settings for the attribute, where you can set the following: - 'type': string, the input type for the attribute. Should be one of the INPUT_ constants. Defaults to INPUT_TEXT. - 'visible': boolean, whether the attribute is visible. One can use this property to control visibility of attributes conditionally. - 'attributes': array, the nested group of sub attributes that will be grouped together, this configuration will be similar to the parent attributes. The label property will be auto set to false for each sub attribute. - 'value': string|Closure, the value to be displayed if the type is set to INPUT_RAW or INPUT_STATIC. This will display the raw text from value field if it is a string. If this is a Closure, your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model $index is the zero based index of the dataProvider, and $widget is the current widget instance. - 'staticValue': string|Closure, the value to be displayed for INPUT_STATIC. If not set, the value will be automatically generated from the value setting above OR from the value of the model attribute. If this is setup as a [[Closure]], your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model, $index is the zero based index of the dataProvider, and $widget is the current widget instance. - 'format': string|array, applicable only for INPUT_STATIC type (and only in tabular forms). This controls which format should the value of each data model be displayed as (e.g. "raw", "text", "html", ['date', 'php:Y-m-d']). Supported formats are determined by [Yii::$app->formatter]. Default format is "raw". - 'hiddenStaticOptions': array, HTML attributes for the static control container and applicable only for [[INPUT_HIDDEN_STATIC]] type. - 'label': string, (optional) the custom attribute label. If this is not set, the model attribute label will be automatically used. If you set it to false, the label will be entirely hidden. - 'labelSpan': int, the grid span width of the label container, which is especially useful for horizontal forms. If not set this will be derived automatically from the formConfig['labelSpan'] property of $form (ActiveForm). - 'labelOptions': array, (optional) the HTML attributes for the label. Will be applied only when NOT using with active form and only if label is set. - 'prepend': string, (optional) any markup to prepend before the input. For ActiveForm fields, this content will be prepended before the field group (including label, input, error, hint blocks). - 'append': string, (optional) any markup to append before the input. For ActiveForm fields, this content will be appended after the field group (including label, input, error, hint blocks). - 'container': array, (optional) HTML attributes for the div container to wrap the input. For ActiveForm, this will envelop the field group (including label, input, error, hint blocks). If not set or empty, no container will be wrapped. - 'inputContainer': array, (optional) HTML attributes for the div container to wrap the input control only. If not set or empty, no container will be wrapped. Will be applied only when NOT using with ActiveForm. - 'fieldConfig': array, the configuration for the active field. - hint: string, the hint text to be shown below the active field. - 'items': array, the list of items if input type is one of the following: INPUT_DROPDOWN_LIST, INPUT_LIST_BOX, INPUT_CHECKBOX_LIST, INPUT_RADIO_LIST, INPUT_MULTISELECT INPUT_CHECKBOX_BUTTON_GROUP, INPUT_RADIO_BUTTON_GROUP - enclosedByLabel: bool, if the INPUT_CHECKBOX or INPUT_RADIO is to be enclosed by label. Defaults to true. - html5type: string, the type of HTML5 input, if input type is set to INPUT_HTML5. - 'widgetClass': string, the classname if input type is INPUT_WIDGET. - 'options': array, the HTML attributes or widget settings to be applied to the input. - 'columnOptions': array, for a Form, it will override columnOptions setup at Form level. For a TabularForm it will allow you to append additional column options for the grid data column.
$form the form instance.
$formName the form name to be provided if not using with model and ActiveForm.
$staticOnly whether all inputs in the form are to be static only

Protected Properties

Property Type Description
$_basicInputs the basic inputs
$_dropdownInputs the dropdown inputs
$_validInputs the allowed valid list of input types

Public Methods

Method Description
init ( )

Protected Methods

Method Description
getInput ( kartik\form\ActiveField $field, string $label = null, string $hint = null ) : kartik\form\ActiveField Generates the active field input by parsing the label and hint.
prepareAttributes ( array &$attributes = [] ) Prepares attributes based on visibility setting
renderActiveInput ( kartik\form\ActiveForm $form, Model $model, string $attribute, array $settings ) : kartik\form\ActiveField Renders active input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.
renderInput ( string $attribute, array $settings = [] ) : string Renders normal form input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.
renderRawActiveInput ( kartik\form\ActiveForm $form, Model $model, string $attribute, array $settings ) : string Renders raw active input based on the attribute settings.
renderRawInput ( string $attribute, string &$id, array $settings = [] ) : string Renders raw form input based on the attribute settings.

Method Details

getInput() protected static method

Generates the active field input by parsing the label and hint.
protected static getInput ( kartik\form\ActiveField $field, string $label = null, string $hint = null ) : kartik\form\ActiveField
$field kartik\form\ActiveField the active field instance.
$label string the label for the field
$hint string the hint for the field
return kartik\form\ActiveField

init() public method

public init ( )

prepareAttributes() protected static method

Prepares attributes based on visibility setting
protected static prepareAttributes ( array &$attributes = [] )
$attributes array the attributes to be prepared

renderActiveInput() protected static method

Renders active input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.
protected static renderActiveInput ( kartik\form\ActiveForm $form, Model $model, string $attribute, array $settings ) : kartik\form\ActiveField
$form kartik\form\ActiveForm the form instance.
$model yii\base\Model the data model.
$attribute string the name of the attribute.
$settings array the attribute settings.
return kartik\form\ActiveField

renderInput() protected static method

Renders normal form input based on the attribute settings. This includes additional markup like rendering content before and after input, and wrapping input in a container if set.
protected static renderInput ( string $attribute, array $settings = [] ) : string
$attribute string the name of the attribute.
$settings array the attribute settings.
return string the form input markup.

renderRawActiveInput() protected static method

Renders raw active input based on the attribute settings.
protected static renderRawActiveInput ( kartik\form\ActiveForm $form, Model $model, string $attribute, array $settings ) : string
$form kartik\form\ActiveForm the form instance.
$model yii\base\Model the data model.
$attribute string the name of the attribute.
$settings array the attribute settings.
return string the generated active input.

renderRawInput() protected static method

Renders raw form input based on the attribute settings.
protected static renderRawInput ( string $attribute, string &$id, array $settings = [] ) : string
$attribute string the name of the attribute.
$id string the input identifier.
$settings array the attribute settings.
return string the form input markup.

Property Details

$_basicInputs protected static property

the basic inputs
protected static $_basicInputs

$_dropdownInputs protected static property

the dropdown inputs
protected static $_dropdownInputs

$_validInputs protected static property

the allowed valid list of input types
protected static $_validInputs

$attributeDefaults public property

the default settings that will be applied for all attributes. The array will be configured similar to a single attribute setting value in the $attributes array. One will typically default markup and styling like type, container, prepend, append etc. The settings at the $attributes level will override these default settings.
public $attributeDefaults

$attributes public property

the attribute settings. This is an associative array, which needs to be setup as $attribute_name => $attribute_settings, where: - attribute_name: _string_, the name of the attribute - attribute_settings: _array_, the settings for the attribute, where you can set the following: - 'type': string, the input type for the attribute. Should be one of the INPUT_ constants. Defaults to INPUT_TEXT. - 'visible': boolean, whether the attribute is visible. One can use this property to control visibility of attributes conditionally. - 'attributes': array, the nested group of sub attributes that will be grouped together, this configuration will be similar to the parent attributes. The label property will be auto set to false for each sub attribute. - 'value': string|Closure, the value to be displayed if the type is set to INPUT_RAW or INPUT_STATIC. This will display the raw text from value field if it is a string. If this is a Closure, your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model $index is the zero based index of the dataProvider, and $widget is the current widget instance. - 'staticValue': string|Closure, the value to be displayed for INPUT_STATIC. If not set, the value will be automatically generated from the value setting above OR from the value of the model attribute. If this is setup as a [[Closure]], your anonymous function call should be of the type: function ($model, $key, $index, $widget) { }, where $model is the current model, $key is the key associated with the data model, $index is the zero based index of the dataProvider, and $widget is the current widget instance. - 'format': string|array, applicable only for INPUT_STATIC type (and only in tabular forms). This controls which format should the value of each data model be displayed as (e.g. "raw", "text", "html", ['date', 'php:Y-m-d']). Supported formats are determined by [Yii::$app->formatter]. Default format is "raw". - 'hiddenStaticOptions': array, HTML attributes for the static control container and applicable only for [[INPUT_HIDDEN_STATIC]] type. - 'label': string, (optional) the custom attribute label. If this is not set, the model attribute label will be automatically used. If you set it to false, the label will be entirely hidden. - 'labelSpan': int, the grid span width of the label container, which is especially useful for horizontal forms. If not set this will be derived automatically from the formConfig['labelSpan'] property of $form (ActiveForm). - 'labelOptions': array, (optional) the HTML attributes for the label. Will be applied only when NOT using with active form and only if label is set. - 'prepend': string, (optional) any markup to prepend before the input. For ActiveForm fields, this content will be prepended before the field group (including label, input, error, hint blocks). - 'append': string, (optional) any markup to append before the input. For ActiveForm fields, this content will be appended after the field group (including label, input, error, hint blocks). - 'container': array, (optional) HTML attributes for the div container to wrap the input. For ActiveForm, this will envelop the field group (including label, input, error, hint blocks). If not set or empty, no container will be wrapped. - 'inputContainer': array, (optional) HTML attributes for the div container to wrap the input control only. If not set or empty, no container will be wrapped. Will be applied only when NOT using with ActiveForm. - 'fieldConfig': array, the configuration for the active field. - hint: string, the hint text to be shown below the active field. - 'items': array, the list of items if input type is one of the following: INPUT_DROPDOWN_LIST, INPUT_LIST_BOX, INPUT_CHECKBOX_LIST, INPUT_RADIO_LIST, INPUT_MULTISELECT INPUT_CHECKBOX_BUTTON_GROUP, INPUT_RADIO_BUTTON_GROUP - enclosedByLabel: bool, if the INPUT_CHECKBOX or INPUT_RADIO is to be enclosed by label. Defaults to true. - html5type: string, the type of HTML5 input, if input type is set to INPUT_HTML5. - 'widgetClass': string, the classname if input type is INPUT_WIDGET. - 'options': array, the HTML attributes or widget settings to be applied to the input. - 'columnOptions': array, for a Form, it will override columnOptions setup at Form level. For a TabularForm it will allow you to append additional column options for the grid data column.
public $attributes

$form public property

the form instance.
public $form

$formName public property

the form name to be provided if not using with model and ActiveForm.
public $formName

$staticOnly public property

whether all inputs in the form are to be static only
public $staticOnly