Đạt Lâm Đạt Lâm - 2 years ago 144
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

Answer Source

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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download