L
L
liltrill2019-09-25 17:43:13
Yii
liltrill, 2019-09-25 17:43:13

How to insert only input without wrapper in yii2 ActiveForm field?

yii2:

<?php $form = ActiveForm::begin(['enableClientScript' => false,]); ?>

<?= $form->field($model, 'name', ['template' => '{input}']) ?>

<?= $form->field($model, 'email', ['template' => '{input}']) ?>

<?= Html::submitButton('Отправить') ?>

<?php ActiveForm::end(); ?>

It returns this html:
<div class="form-group field-testform-name required">
   <input type="text" id="testform-name" class="form-control" name="TestForm[name]" aria-required="true">
</div>

How can I return only input?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-09-25
@liltrill

Set up fieldConfig for the whole form, then you can remove the div with class form-control

<?php $form = ActiveForm::begin([
        'fieldConfig' => [
            'options' => [
                'tag' => false,
            ]
        ]
    ]); ?>

Instead of false , you can specify your own tag.
But there is one "BUT", the validation stops working, you have to mess around to restore it, it is possible to do ajax validation.

G
Gomonov, 2019-09-25
@Gomonov

echo $form->field($model, 'demo', [
     'template' => '{input}{error}{hint}'
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question