Hi,
I’m not sure what’s up but I’m trying to normalize input before validation and no matter what I do, a validation rule kicks in that shows that the normalization is not taking place.
Method 1: Using a "filter" Validation Rule
I’m including these rules in this order in the rules array:
[['some_attribute'], 'filter', 'filter' => function ($value) { return intval($value); }], // (yes, I know I can just use 'filter' => 'intval')
[['some_attribute'], 'integer'],
yet for some reason, if I enter ‘1234a’ into the input field, I get “some_attribute must be an integer” as the error result in client-side validation.
Method 2: Overriding "beforeValidate":
public function beforeValidate()
{
$this->some_attribute = intval($this->some_attribute);
return parent::beforeValidate();
}
this didn’t work either. Both methods ended up with the same result. The integer rule kicked in preventing submission of the form.
Does anyone have any ideas as to why this might be happening?