I found this extension for Yii 1.1
but don't see any relevant extension for Yii 2
. So I'm wondering if there is one or is it built-in by default?
Also, when data properties gets set in your model
for a form such as:
namespace app\models;
use yii\base\model;
class SignupForm extends Model {
public $company_name;
public $first_name;
public $last_name;
public $email;
public $username;
public $password;
public $password_again;
/**
* Validation rules
*/
public function rules() {
return [
// Format some data
[['company_name', 'first_name', 'last_name', 'email', 'username', 'password', 'password_again'], 'trim'],
['username', 'filter', 'filter' => 'strtolower'],
// If company scenario, require company name
['company_name', 'required', 'on' => 'company'],
//..............
];
)
}
Is this data sanitized by default or does one have to sanitize it themselves?
So I guess my main question is - how do I sanitize data with Yii 2?
You can try using HTMLPurifier for sanitizing input like so:
[['attr1', 'attr2'], function ($attribute) {
$this->$attribute = \yii\helpers\HtmlPurifier::process($this->$attribute);
}],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With