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

Multi tool use
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





@Developer Ajdevtech your problem is resolve ?
– vishuB
Jul 3 at 7:56





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.

Irtar30RJqnu Wn4o ejp0mBk,VZV0hYUSBdM3LWq6,5dsg7Bql3q KxwKOK s45rDp,v,WB,3
mI6aDS IDR3kjVCmm5YERADvDtLGzImLMqzelKsolWfZjvDnY0AvIpFrPa,9GW7jIrNqWvRueLGX5dP4pr6

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications