O
O
Oleg Trubin2014-12-15 22:04:37
Yii
Oleg Trubin, 2014-12-15 22:04:37

[Yii2] How to add id to form fields when using ActiveForm?

Hello.
Actually a subject.
Available:

<?php $form = ActiveForm::begin(['id' => 'form-add-video']); ?>
            <?= $form->field($model_video_form, 'name')->label('Название (для отображения в списке)') ?>
            ...

How can I add an id attribute to a field?
Thanks in advance for taking the time to help me :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Viktor Chistyakov, 2017-01-30
@vityachis

<?= $form->field($model, 'name', [
    'inputOptions' => [
        'id' => 'uniqueID',
    ],
])->label('Название') ?>

Only it does not add, but replaces the already set attribute)

M
Maxim, 2014-12-15
@Frapsy

<?=$form->field($model_video_form,'name',['id'=>'field_id'])->label('..')?>

A
Alexander Zelenin, 2014-12-16
@zelenin

<?=$form->field($model_video_form,'name',['options' => ['id'=>'field_id']])->label('..')?>

I
Igor Vasiliev, 2020-07-10
@Isolution666

For example like this:

<?php $form = ActiveForm::begin(['id' => 'form-add-video']); ?>
            <?= $form->field($model_video_form, 'name')->textInput(['id' => 'your_id', 'placeholder' => 'your place holder'])->label('Название (для отображения в списке)') ?>
            ...

We enter the data array in square brackets in textInput() - and that's it :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question