T
T
Taras Labiak2015-06-10 14:24:31
Yii
Taras Labiak, 2015-06-10 14:24:31

Why is an empty form displayed in Yii 2?

If the code is _form.php

<?php
use yii\widgets\ActiveForm;
?>
<div class="user-form">
    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'email')->textInput() ?>
    <?= 1//Html::activeTextInput($model, 'email') ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord
            ? Yii::t('app', 'Create')
            : Yii::t('app', 'Update'),
            ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

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

</div>

That the server will generate
6bdabfb4fdb543faac867c7a8f7df5d9.png
There are no errors in the log.
If <?= $form->field($model, 'email')->textInput() ?> is replaced by <?= Html::activeTextInput($model, 'email') ?> then the display is fine Custom fields have been added to the User.php
29cd6a14dbf940db8e0a7b04998b33b8.png
model generated from the yii2-app-advanced template

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cloud_zurbag, 2015-06-11
@kissarat

I checked it myself. Connected the specified model and the used view code.
Everything works, only two errors:
1) Validator ['username', 'maxlength' => 32], invalid
should be ['username', 'string', 'max' => 32]
2) use yii\helpers\ HTML; I needed to connect.
After that it worked...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question