1
votes

I have defined the custom validation rule:

['Email', 'checkUniqueExistence'],

public function checkUniqueExistence($attribute, $params)
{
        $email = $this->$attribute;

        $checkUniqueExistenceForEmail = Parents::find()->where([ 'Email' =>  $email])->One();

        $resendActivationLink = Html::a('Resend Link','#');

        if(count($checkUniqueExistenceForEmail) > 0){
            if($checkUniqueExistenceForEmail->IsAccountActivated == Yii::$app->params['IsAccountActivatedTrue']){
                $this->addError($attribute, 'Email address already exists');
            }
            else{
                $this->addError($attribute, 'You haven\'t activated your account. Request '.$resendActivationLink);
            }
        }

}

But link does not generate. It is displayed as a string. I got the following output after submitting the form:

You haven't activated your account. Request <a href="#">Resend Link</a>

Is it possible to display link in addError() method?

1
A more effective method will be to display the Resend Link conditionally based on whether the error object is set or not .. - Akhil Thayyil
eg : if($this->hasError) { show_link } else { hide_link } , you can add something like this in your view - Akhil Thayyil
Thanks I will give it a try. But still the question arises why does the addError method does not render HTML? - Chinmay Waghmare

1 Answers

6
votes

Pass this configuration array to ActiveField

'errorOptions' => ['encode' => false]