Generating labels and inputs separately [SOLVED]

Hello. I have form, which is hard to generate with field(), because layout contains a lot of html between label, input and error. Instead of fighting with template option, in Yii1 I could use CHtml::activeTextField, CHtml::activeLabel and form was normally working with validation. How I can do it in Yii2?

Yii2 Active fields are wrapped in bootstrap. Perhaps you can use the activeform itself and get the desired layout.

activeLabel(), activeTextInput() and likes are implemented in yii\helpers\Html. They are the equivalents of CHtml::activeXXXX in Yii 1.1.

Please refer to the API documentation of yii\helpers\Html.

The extended yii\bootstrap\(Base)Html also supports them just with the same name and the signatures.

Referring to this: client-side validation will not work and this is by design. Maybe there is another way?


I found solution here:

echo $form->field($model, 'fieldname')->begin();

        echo Html::activeLabel($model,'fieldname');

        echo Html::activeTextInput($model, 'fieldname');

        echo Html::error($model,'fieldname', ['class' => 'help-block']);

echo $form->field($model, 'fieldname')->end();

I think this is important and should be mentioned in docs.