Frage

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!'),
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top