Yii2 removing white space left and right of each post data?

Multi tool use
Yii2 removing white space left and right of each post data?
Function is:-
want to use trim() method in beforeAction controller for removing white space left and right of each post data ?
public function beforeAction($action)
{
Yii::$app->request->post() // I want to trim all post data
return parent::beforeAction($action);
}
1 Answer
1
Better way to use trim
in model rules like this
trim
public function rules()
{
return [
[['here_field_name'], 'filter', 'filter' => 'trim'],
];
}
or
public function rules()
{
return [
[['here_field_name'], 'trim'],
];
}
Refer Yii2 Core Validators
can I use your shared rules on controller ? Yes, I have fixed it via adding code on web.php. I used following code to trim each post data 'on beforeAction' => function ($event) { $_POST = filter_var($_POST, FILTER_CALLBACK, ['options' => 'trim']); }
– Developer Ajdevtech
Jul 4 at 11:12
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
@Developer Ajdevtech your problem is resolve ?
– vishuB
Jul 3 at 7:56