I've written a plugin which intercepts the user.onSaveUser event.

However if the save fails the user is still redirected to the page specified in the 'redirect' parameter/field of the form. How do I redirect them back to the form with errors and then access those errors?

I've tried craft()->urlManager->setRouteVariables() but still being returned to the page/URL specified in the original form. If I remove the redirect field from the front-end form I am redirected to the form on error but cannot access the errors sent in craft()->urlManager->setRouteVariables().

Any thoughts on how to specify the redirect destination depending on success/fail and also how to send/access the offending error messages in my original template?

1 Answer 1


As your code is running during an event, returning the request to the page has to be done a bit more explicitly than when you are performing similar behavior in a controller.

While I'm probably not the best person to explain this in detail, the code below gives one example I was provided in how you can set your route variables and end the request:

if ($errors)
        'errors' => $errors

    $route = craft()->urlManager->parseUrl(craft()->request);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.