php - Running functions on form data before/during validation in Yii 2 -


ok, example if entering username , want make lowercase before or @ beginning of validation (in rules method) how can this?

i know can similar trim such as:

[['company_name', 'first_name', 'last_name', 'email', 'username', 'password', 'password2'], 'trim'] 

but assume doesn't support function?

so, want run strtolower function on username, way go doing this? need use beforevalidate method or can this?

['username', 'makelower']  public function makelower($attribute, $params) {                     $this->$attribute = strtolower($this->$attribute); } 

you can use filtervalidator.

['username', 'filter', 'filter' => 'strtolower'] 

filtervalidator not validator data processor. invokes specified filter callback process attribute value , save processed value attribute. filter must valid php callback following signature:

function foo($value) {...return $newvalue; } 

many php functions qualify signature (e.g. trim()).


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -