I
I
Igor Vasiliev2018-09-17 23:00:27
Yii
Igor Vasiliev, 2018-09-17 23:00:27

How to insert a hyperlink in addError in Yii2?

It would seem a simple question, how to put a link into validation, but in fact neither decoding nor conversion of HTML entities helps, that is, the usual built-in php functions, - "addError" - completely ignores
Yii::$app->session->getFlash();- does not see at all, without addError validation is ignored, that is in the end, we get the error text with the html code of the link at the output.

<?=Html::encode();?>
<?=Html::decode();?>

They won't help either, and ENT_QUOTES is used in decode, which ignores quotes
. In general, the point is that it's not so easy to insert a link into validation, but I think it's possible.
Who faced? How to implement it?
If there are no ways, then I will implement it through JavaScript, since with its help it is generally easy to implement this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-09-18
@Isolution666

Actually, you can.
I didn't realize right away.
Here is how it should be done.

// В ActiveForm
$form->field($model, 'password',[
    'errorOptions' => [
        'encode' => false,
    ]
])->passwordInput() 

// В модели
$this->addError('password', UsersModule::t('module', 'ERROR_WRONG_USERNAME_OR_PASSWORD', ['link' => Html::tag('a','test')]));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question