Đạt Lâm Đạt Lâm - 10 months ago 59
PHP Question

yii2:active form generate code

I have this code in Yii2:

<?= $form->field($model, 'username')->label(false); ?>
<?= $form->field($model, 'password')->label(false); ?>

It generate this:

<div class="form-group field-validate-username required has-success">
<input type="text" id="validate-username" class="form-control" name="Validate[username]">
<div class="form-group field-validate-password required has-success">
<input type="text" id="validate-password" class="form-control" name="Validate[password]">

but I want to do this:

<div class="form-group">
<input type="text" name="MViewer[first_name]" class="form-control" id="mviewer-first_name">
<input type="text" name="MViewer[last_name]" class="form-control" id="mviewer-last_name">

Sorry for my bad English


You need to use something like this

<div class="form-group"> <?= Html::activeTextInput($model, 'username', ['class' => 'form-control']) ?> <?= Html::activeTextInput($model, 'password', ['class' => 'form-control']) ?> </div>