Usually this would look like this:
This is all good unless somebody is inserting spaces. At that point the validation returns true and saves spaces into your database table. I guess that is not the desired result. One solution would be to trim individually every input in the controller before validation. That would result in too many lines. CakePHP should have this built in.
The other solution for doing this and loosing those extra lines it is to put the following code in your app_controller.php:
<?php class AppController extends Controller { function whitespace(&$value, &$key){ } function beforeFilter(){ } } ?>
Doing this the values are trimmed and the validation rule returns false for inputs containing only spaces.
Enjoy!
5 comments so far
Post your comment