Html Encoding In Detail View

How to use HtmlPurifier in Yii2. Currently my form inputs are not being html encoded which opens a chance for CSS attacks.

Any examples?


I have a detail view like this.

    <?php echo DetailView::widget([

    'model' => $model,

    'attributes' => [






         'label' => 'Company',

         'value' => $model->user->c->name,






]); ?> 


public function rules()


    return [

        [['user_id', 'first_name', 'last_name', 'address', 'job_designation'], 'required'],

        [['user_id'], 'integer'],

        [['first_name', 'last_name', 'address', 'job_designation', 'about'], 'string']



I gave <script>prompt(‘some question’)</script> as firstname and last name. Upon taking the view page,it is prompting for the same.But job_designation is not prompting when I test that field.

But view page source is giving as,


What is happening here and how to fix it?