Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to specify validation in validation rules. Yii2?
I have this rule in my model:
[['name', 'email', 'phone', 'address'], 'required'],
Answer the question
In order to leave comments, you need to log in
Good evening.
Why do you need htmlspecialchars when writing to the database?
Another thing is when outputting from the database to the site page, then yes, htmlspecialchars () is used.
But for this, yii2 has two methods, Html::encode and Html::decode() , and they just use htmlspecialchares().
So use the capabilities of the framework-a. When outputting to the browser, use Html::encode().
And how do you have mandatory fields associated with htmlspecialchars?
There are events beforeSave, beforeValidate and others where you can make any transformations, what does the 'required' validator have to do with it?
No matter how strange it may sound, the area of responsibility of the validator is data validation. The validator does not change the data, it only tells the model whether it stores the correct data.
If you want validation to modify the data - don't use a framework - use the best practices of global variables, spaghetti code, GOD objects, magic numbers and other technologies
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question