Question

I have this validation rule in an user table that makes sure user email is unique. Now I don't want to skip this validation, but want to give an option to the user to choose the existing user data and insert relevant data to another relation table. Is there any way to catch if this particular validation rule fails and then redirect to another controller/action, but I don't want to redirect when any other rule fails.

array('email','unique','message'=>'{attribute}:{value} already exists!'),
Was it helpful?

Solution

Yes ...

Oh, are you asking how to do the above? ;-)

In your controller where you save your model, if saving doesn't work, check for errors for that particular attribute:

$this->getError(<attributeName>);

If the message matches your error above, redirect in your controller. Otherwise, handle the errors as you normally do

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top