I have a simple create new account page with username, email, confirm email, password, and confirm passwords fields. All of the validations goes under the User model and currently all the input fields are required.
Once the user logs in, there’s a setting page where they can update their email and password. The input fields are email, confirm email, password, and confirm password (same input fields as the create an account page sans username field). However, I want the validations to be different under settings with none of the fields being required. How would I approach this problem without affecting the validation rules for the create new account page? Your help is much appreciated.
It doesn’t seem like you really need ANY of the fields “required” as CakePHP thinks of it.
“Required” as far as CakePHP is concerned means that that field MUST be submitted any and every time that model is saved. It has nothing to do with whether or not there is content in the field (which is ‘notEmpty’).
So – for your case, you could probably just set up the normal data validation rules for each field (ie minLength, notEmpty, valid email…etc etc, etc, and be just fine for both pages. Any data that’s submitted must pass the validation – and if it’s not submitted, no big deal.
You could always set:
if you need to verify that that field exists in the data for a save or update… but I’ve personally never found that necessary and have created many pages like you’ve described.
Per the book [here]: