How to add custom link to Yii 2 validation error message?

I would like to add a custom link in a validation confirmation based on Yii 2 model.

I am using the following code at the moment -

public function rules()
{
  return [
    ['email', 'required'],
    ['email', 'email'],
    ['email', 'unique', 'targetClass' => '\common\models\User', 
                        'message' =>   'Email address has already been taken.'],
  ];
}

      

I want this message to be displayed like this:

"Email address is busy. Already registered? Then login here ."

How can I achieve this?

+3


source to share


1 answer


As noted in the comment, you need to add a link to your parameter message

, and also to prevent link encoding, you need to set the encode parameter to false.



$form->field($model, 'email', ['errorOptions' => ['class' => 'help-block' ,'encode' => false]])->textInput()

      

+6


source







All Articles