4
votes

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!!!

2
Try : 'options' => ['class' => 'form-horizontal'], - Yasin Patel

2 Answers

8
votes

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

Change your use statement.

4
votes

In boostrap you can use

<form class="form-inline">  // for inline fields form

or

<form class="form-horizontal">  // for horizonatal  fields form

eg:

  <?php $form = ActiveForm::begin([
      'layout' => 'horizontal',
      'action' => ['index'],
      'method' => 'get',
      'class' => 'form-horizontal',    
  ]); ?>