Answers.Body: <p>You could use the <code>craft()-&gt;userSession-&gt;setFlash('your message here');</code> functionality. </p>
  
  <p>How it works is explained in <a href="https://craftcms.stackexchange.com/a/15152/6991">this</a> or <a href="https://craftcms.stackexchange.com/a/4602/6991">this</a> answer for example but it boils down to setting the message in your event handler and then checking in your template if there's a message and if there's one, display it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-24T06:44:54.067Z
Answers.LastActivityDate: 2017-10-24T06:44:54.067Z
Answers.UserDisplayName: mrsmn
Body: <p>Is there a way to send errors back to the set password form?  </p>
  
  <p>I am listening to the <code>users.onBeforeSetPassword</code> event in which I want to confirm that the string in a confirm password field is the same as in the newPassword field.  </p>
  
  <pre><code>craft()-&gt;on('users.onBeforeSetPassword', function(Event $event) {
         // Only do anything if it is a front end submission
         if(craft()-&gt;request-&gt;isSiteRequest())
         {
             $newPassword = craft()-&gt;request-&gt;getPost('newPassword');
             $passwordConfirm = craft()-&gt;request-&gt;getPost('passwordConfirm');
             if(isset($passwordConfirm) &amp;&amp; strcmp($newPassword, $passwordConfirm) !== 0)
             {
                 $event-&gt;params['user']-&gt;addErrors(array('newPassword' =&gt; Craft::t('Passwords do not match')));
                 $event-&gt;performAction = false;
             }
         }
     });
    }
  }
  </code></pre>
  
  <p>This does prevent the user from resetting their password but doesn't send a error message back to the template.  How can I pass a variable back to the template so I can show the user their error?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-24T05:50:42.860Z
Comments.Text: This is only possible when you copy and paste the controller action in your custom controller. It takes usually about 2-3 minutes to do this. If you don't want this for any reasons you can include Javascript after setting your  `performAction` and include the html by yourself. You just have to append an unsorted list with the message.
Comments.UserDisplayName: Robin Schambach
Tags: <plugin-development><events>
Title: Confirm Password on Set Password Form
ThreadText: # Confirm Password on Set Password Form
  
  (Asked by: username_0 on 2017-10-24)
  
  Is there a way to send errors back to the set password form?
  
  I am listening to the `users.onBeforeSetPassword` event in which I want to confirm that the string in a confirm password field is the same as in the newPassword field.
  
  ```
  craft()->on('users.onBeforeSetPassword', function(Event $event) {
         // Only do anything if it is a front end submission
         if(craft()->request->isSiteRequest())
         {
             $newPassword = craft()->request->getPost('newPassword');
             $passwordConfirm = craft()->request->getPost('passwordConfirm');
             if(isset($passwordConfirm) && strcmp($newPassword, $passwordConfirm) !== 0)
             {
                 $event->params['user']->addErrors(array('newPassword' => Craft::t('Passwords do not match')));
                 $event->performAction = false;
             }
         }
     });
    }
  }
  
  ```
  
  This does prevent the user from resetting their password but doesn't send a error message back to the template. How can I pass a variable back to the template so I can show the user their error?
  
  **Tags:** plugin-development, events
  
  > **Comments:**
  > **username_1**: This is only possible when you copy and paste the controller action in your custom controller. It takes usually about 2-3 minutes to do this. If you don't want this for any reasons you can include Javascript after setting your  `performAction` and include the html by yourself. You just have to append an unsorted list with the message.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-10-24. Score: 2
  
  You could use the `craft()->userSession->setFlash('your message here');` functionality.
  
  How it works is explained in [this](https://craftcms.stackexchange.com/a/15152/6991) or [this](https://craftcms.stackexchange.com/a/4602/6991) answer for example but it boils down to setting the message in your event handler and then checking in your template if there's a message and if there's one, display it.
  
  
  ---
  
  