Applying ucwords(strtolower(name)) to form data before submitting to DB in CakePHP

38 Views Asked by At

Assume a user fills a form and puts his name like AndReW(Mixed lower and uppercase), I want to get this form data, convert it to a form like this Andrew, and then submit it to the database.... I dont want to submit it in this form AndReW, instead like this Andrew..... (I know i can use ucwords(strtolower(AndReW)), but where exactly i'm I supposed to put this code in CakePHP)

I tried ucwords(strtolower(field_name)) in the model(in virtual fields), but it didn't work out.. Where exactly should I put this code? In the model or??

1

There are 1 best solutions below

0
Andrew Muwanguzi On

Was able to figure it out... Added this code to the controller action

if(isset($this->data['modelName']['first_name']) && $this->data['modelName']['first_name'] != '') { $this->request->data['modelName']['first_name']= ucwords(strtolower($this->data['modelName']['first_name'])); }

This inserts first_name in the database in the desired case of the letters....And it worked out