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.
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 properform
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 betweenActiveForm::begin()
andActiveForm::end()
methods calls.