Hello,
I am very new to Yii and am coming from CodeIgniter. I’ve just starting out with 1 table in SQLite so I can see what is going on, etc.
I have noticed that the fields do not trim/strip whitespaces and I’m wondering how I can do this.
In the docs it says I have to use CFilterValidator but I am unsure of how to use it.
My rules inside the ‘Workers’ model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name', 'required'),
array('birthMonth, age, weight', 'numerical', 'integerOnly'=>true),
array('wage', 'numerical'),
array('nickname, gender, picture, speaks, nationality', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, name, nickname, gender, birthMonth, age, weight, picture, speaks, nationality, wage', 'safe', 'on'=>'search'),
);
}
I tried:
array(‘name’, ‘required’, ‘trim’)
This doesn’t work and gives me an error.
I tried:
array('name', 'required', 'filter'=>trim)
This doesn’t work and gives me an error.
I tried, following this comment:
To do this:
array('name', 'required', 'filter'=>array($this, 'trim')),
This gives me an error:
Property "CRequiredValidator.filter" is not defined.
All I want to do is trim the whitespace from the field.
How can I best achieve this? And why isn’t whitespace taken care for me?
Thanks.