I have my login and registration forms in elements that reference the users controller and login() and register() actions. When I use this element in a modal or on a page co
I've solved this issue in the past with this PersistentValidation component. The way you set it up is by including the PersistentValidation component in your UsersController, and any other controller where you're planning to include the login/register elements.
Your login/registration forms would submit to their respective controller actions. If validation fails, the action would redirect back to the referring page. For example:
if (!$validated) {
$this->redirect($this->referer());
}
The view invoked by the action to which you redirect will be automagically seeded with the validation errors from the previous request.
This works, behind-the-scenes, by storing the validation errors in a session variable, and retrieving these errors after the redirect, making them available for the current request's views/elements. You could do this yourself, but the component makes it very painless to use.