Consider following scenario:
I am building a user registration page for my site. I have a FormModel for the registration web form and a ActiveRecord class for the account. After the form is valiated, its attributes are massively assigned to newly created AR instance and second one is saved.
I have 2 questions:
Where is right to validate?
Field like "passowrd", "email" and "username" can be validate in the AR class and also in the FormModel. Where is better?
How to bubble the validation errors?
The uniqueness of username is validated in the AR model. When there is already same username in the database, I need to show error. But I am passing the form model to the view. Is there any kind of "shortcut" to pass the errors from the AR model to the FormModel? Or - is there any undocumented way to check for uniqueness in the FormModel? (the documentation says "no" to this one)…
Thanks in advance!