views:

88

answers:

1

I have a single model in CakePHP that has multiple forms on different pages of the site that I would like to validate differently even where the field name is the same - I have discovered that you can set 'on' to create|update which has been a handy discovery but I am wondering if there is any other way of explicitly declaring rules based on the form that was submitted?

Just to rephrase for clarity, form a and form b contain fields of the same name, but if form a is submitted the fields in question should be validated differently than if they were submitted from form b. Possible?

A: 

Yes, this has been done before and is possible with the right code. (See links below.)

The User model is a common place for this technique as you generally want different validation rules when people are submitting account-related forms.

For example, when registering a user you check if their email address is unique and doesn't exist in the database, but when resetting a user's password you instead want to check that their email does exist.

deizel
Honestly, that's exactly the use which inspired the question. Not sure how I couldn't find this on Google, must have been a lack of caffeine-powered keywords.
mwaterous