If layout
is set to horizontal
a horizontal form is rendered.
<?php $form = ActiveForm::begin(['layout' => 'horizontal']) ?>
Here by default the template
is set to
{label} {beginWrapper} {input} {error} {endWrapper} {help}
,
which will use 3 columns, one for label (col-sm-3
), input (col-sm-6
)
and help text (col-sm-3
) each. Error messages get rendered below the input. The column
arrangement can easily be changed, though (see below).
Following is a list of the most common form elements to exemplify different options and validation states.
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-4',
'offset' => 'col-sm-offset-4',
'wrapper' => 'col-sm-8',
'error' => '',
'hint' => '',
],
],
]) ?>
<?php ActiveForm::end(); ?>