I have been trying to define an anonymous function in my model’s validation rules as follows:
public function rules() {
return [
[['field1','field2','field3'], 'filter',
'filter'=>function($value) {
$value = trim($value);
if (empty($value)) return null;
return $value;
}
],
// Other validation rules
];
}
This definition creates a strange behavior, the session POST value is not set properly and Yii Debugger does not show at the bottom of the page! I have looked everywhere and it seems correct to me. Note that if I modify the rule as follows:
public function rules() {
return [
[['field1','field2','field3'], 'nullSetter', 'SkipOnEmpty' => false],
// Other validation rules
];
}
and the nullSetter function is exactly as above, everything works juts fine. What am I doing wrong? Can this be a bug?
Thank you!