I have a html form to save projects in cakephp. i want to restrict the user to save same project name. If any body type the same project name for that i applied the ‘unique’ validation in model but if anybody enter the same name with spaces before or after the project name it accepts it and store into the database.THat is the issue. I want to remove that extra spaces before save.
Please help.
Just as an addition to @Prasantn Bebdra’s answer and since the asker doesn’t know where and how to use
trim().To trim all the data that is comming from POST in your controller (just before the call to
Model->save()) do:You can also use this in the
Modelby utilizing one of it’s callbacks for example beforeValidate() or beforeSave() where in your case it should be better to use beforeValidate since you’d probably also want to validate this data afterwards.You should also notify the user that the input will be trimmed and maybe also do such trimming on the client-side (before the POST) – check this StackOverflow answer out.