Answers.Body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>if ($errors)
  {
      craft()-&gt;urlManager-&gt;setRouteVariables(array(
          'errors' =&gt; $errors
      ));
  
      $route = craft()-&gt;urlManager-&gt;parseUrl(craft()-&gt;request);
      craft()-&gt;runController($route);
      craft()-&gt;end();
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-02T15:38:28.840Z
Answers.LastActivityDate: 2016-06-02T15:38:28.840Z
Answers.UserDisplayName: Ben Parizek
Body: <p>I've written a plugin which intercepts the <code>user.onSaveUser</code> event. </p>
  
  <p>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? </p>
  
  <p>I've tried <code>craft()-&gt;urlManager-&gt;setRouteVariables()</code> 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 <code>craft()-&gt;urlManager-&gt;setRouteVariables()</code>.</p>
  
  <p>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?</p>
  
Tags: <plugin-development><usermodel><redirection>
Title: onSaveUser event - cannot redirect or access errors
ThreadText: # onSaveUser event - cannot redirect or access errors
  
  (Asked by: username_0 on 2016-06-01)
  
  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?
  
  **Tags:** plugin-development, usermodel, redirection
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-02. Score: 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)
  {
      craft()->urlManager->setRouteVariables(array(
          'errors' => $errors
      ));
  
      $route = craft()->urlManager->parseUrl(craft()->request);
      craft()->runController($route);
      craft()->end();
  }
  
  ```
  
  
  ---
  
  