【发布时间】:2019-05-29 08:35:06
【问题描述】:
我正在使用 yii2 的 ActiveForm,我想自定义验证错误。我想在工具提示上显示错误。
这是我的表格
<?= $form = ActiveForm::begin(['id' => 'login-form','method'=>'post']); ?>
<?=
$form->field($model, 'email')
->textInput([
'class'=>'form-control login_email',
'placeholder'=>'Email'
/*'onfocus'=>"this.value = '';",
"onblur"=>"if (this.value == '') {
this.value = 'Email';
}"*/
])
->label(false);
?>
<?=
$form->field($model, 'password')
->passwordInput([
'class'=>'form-control',
'placeholder'=>'Password'
])
->label(false);
?>
<input type="text" name="hidden" value="login" hidden="true">
<p class="forgot">
<a href="<?= Yii::$app->urlManager->createUrl(['site/request-password-reset']); ?>">
Forgot Password?
</a>
</p>
<div class="form-group">
<?= Html::submitButton('Log In', ['class' => 'sign-in','name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
如果有人对此有任何想法,请告诉我。
【问题讨论】:
-
我已经回答了之前提出的另一个问题,错误需要在
anchor的title属性内显示,它解决了您所问的问题,因为工具提示也适用于标题,如果对您有帮助,请参阅here
标签: php yii2 tooltip custom-errors yii2-validation