Strip tags to all fields

Hello, How to can strip html tags for all fields before save?

In simple php I can use strip_tags() function, however I think that YII2 can offer a better solution to change do it in a bulk action.

Thank you in advanced.

You can use for example filter validation rule:




public function rules()

{

    return [

        [

            ['attribute1', 'attribute2', 'attribute3', /* ... */],

            'filter',

            'filter' => function ($value) {

                return strip_tags($value);

            }

        ],

    ];

}



Also take a look at yii\helpers\HtmlPurifier class for (better) removing HTML tags.

1 Like