Yii2 Horizontal form

Chhorn Soro picture Chhorn Soro · Feb 14, 2017 · Viewed 8.8k times · Source

What I want to do is to change from bootstrap vertical to horizontal form and this is what I've tried:

<?php $form = ActiveForm::begin([
    'layout' => 'horizontal',
    'action' => ['index'],
    'method' => 'get',
    'fieldConfig' => [
        'horizontalCssClasses' => [
            'label' => 'col-sm-2',
            'offset' => 'col-sm-offset-2',
            'wrapper' => 'col-sm-4',
        ],
    ],
]); ?>
    <div class="row">
        <div class="col-md-6">
            <?= $form->field($model, 'firstname') ?>
            <?= $form->field($model, 'lastname') ?>
       </div>
        <div class="col-md-6">
            <?= $form->field($model, 'email') ?>
            <?= $form->field($model, 'bla') ?>
       </div>
    </div>
<?php ActiveForm::end() ?>

but it gave me an error Setting unknown property: yii\widgets\ActiveForm::layout Please help!!!

Answer

Bizley picture Bizley · Feb 14, 2017

For layout option to work ActiveForm must be instance of yii\bootstrap\ActiveForm instead of yii\widgets\ActiveForm.

Change your use statement.