No error message show in yii2

9.3k views Asked by At

I cann't not show the error message.

This is my site code.

<div class="login_wrapper">
<div class="row">
    <div class="left_block">
        <div class="row">
            <form class="col-md-12 col-sm-12 col-xs-12">
                <h2 class="login_heading">Login</h2>
                <div class="row">
                    <?php $form = ActiveForm::begin([
                        'fieldConfig' => [
                            'template' => "{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                        ]]); ?>
                    <div class="input-field col-md-12 col-sm-12 col-xs-12">
                        <?= $form->field($model, 'username', [
                            'inputTemplate' => '<i class="ion-person prefix"></i>{input}<label for="icon_prefix-2" >
                            Username</label>',])->textInput(['id' => 'icon_prefix-2', 'class'=>' validate', 
                            'autocomplete' => 'off'])?>
                    </div>
                    <div class="input-field col-md-12 col-sm-12 col-xs-12">
                        <?= $form->field($model, 'password', [
                            'inputTemplate' => '<i class="ion-locked prefix"></i>{input}<label for="icon_prefix-2" >
                            Password</label>',])->passwordInput(['id' => 'icon_prefix-3', 'class'=>'validate', 
                            'autocomplete' => 'off', 'onpaste' => 'return false']) ?>
                    </div>                                
                    <div class="clearfix"></div>
                    <?= Html::submitButton('Login', ['class' => 'btn btn-primary btn-block', 'name' => 'login-button']) ?>
                    <?php ActiveForm::end(); ?>
                </div>
            </form>
        </div>
    </div>
</div>

It does not show the error message even I empty all the input field.

2

There are 2 answers

1
Tony On BEST ANSWER

You need to remove <form class="col-md-12 col-sm-12 col-xs-12"> and </form> from your page, because <?php $form = ActiveForm::begin();?> generates proper form tag and csrf-token if needed.

Also check if your model have validation rules. Yii2 provides js field validation before submit by-default (for default validators).

If js validation somehow pass by, but you sure that it should not, add <?= $form->errorSummary($model)?> somewhere between ActiveForm::begin() and ActiveForm::end() methods calls.

1
ScaisEdge On

Check if in yourApp/web/index.php these are setting :

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

and look in Yii debugger