Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a HTML tag in Yii2 form error summary

I am trying to display a link in error message in login for, but it is not working.

The error message in LoginForm valdiation:

$this->addError($attribute, 'Your account has been disabled. <a href=""> Enable It</a>');

In login.php (view):

<?= $form->errorSummary($model); ?>

I tried like below, but not working:

 <?= $form->errorSummary($model,['errorOptions' => ['encode' => false,'class' => 'help-block']]); ?>

I am getting the following output instead of rendered a tag:

error summary

like image 601
sridhar Avatar asked Nov 15 '18 10:11

sridhar


1 Answers

You need to disable encoding at ActiveForm level using encodeErrorSummary property, if you want to use $form->errorSummary($model):

<?= $form = ActiveForm::begin([
    'id' => 'login-form',
    'encodeErrorSummary' => false,
    'errorSummaryCssClass' => 'help-block',
]) ?>

<?= $form->errorSummary($model) ?>

Alternatively you may use Html::errorSummary() directly:

<?= Html::errorSummary($model, ['encode' => false]) ?>
like image 169
rob006 Avatar answered Nov 17 '22 11:11

rob006