Answers.Body: <p>You're importing the wrong class for Users. Try <code>use craft\elements\User</code> instead of <code>use craft\fields\Users</code>. <code>elements\User</code> extends the base <code>elements</code> class which has the event you're trying to use - Here it is in the class reference with an example:</p>
  <p><a href="https://docs.craftcms.com/api/v5/craft-base-element.html#event-after-save" rel="nofollow noreferrer">https://docs.craftcms.com/api/v5/craft-base-element.html#event-after-save</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-22T16:33:34.857Z
Answers.Text: This doesn't work either. Produces error on the calling Event:
     Event::on(Users::class, Users::EVENT_AFTER_SAVE, 
  Is there even a Users::EVENT_AFTER_SAVE? I swapped this for element but still the results are that the user data is saved but the module does not catch the event.
  
  Looking here https://docs.craftcms.com/api/v5/craft-elements-user.html#events there is no user save event.
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-22T16:54:15.207Z
Answers.Text: It inherits from base\Element, so the event should still work. Note that the class is called `User` in the singular, not `Users`. Check for any other typos.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-22T16:58:34.283Z
Answers.Text: Thx James - still no dice
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-22T17:08:16.333Z
Answers.Text: Interesting - its saving and now I am finding user.errors is saying "unable to save your profile" - its coded in template. How can I get the console for user in frontend when they are not privileged i wonder.?
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-22T08:11:04.313Z
Answers.LastActivityDate: 2024-10-22T08:11:04.313Z
Answers.UserDisplayName: James Smith
Body: <p>I have a module and I want to listen for the saving of a user profile in the front end. Module looks like this.</p>
  <pre><code>use Craft;
  use yii\base\Event;
  use craft\events\UserEvent;
  use craft\fields\Users;
  use craft\events\ModelEvent;
  use yii\base\Module as BaseModule;
  </code></pre>
  <p>My public init looks like this:</p>
  <p>public function init(): void
  {
  Craft::setAlias('@modules/fetchprofile', <strong>DIR</strong>);</p>
  <pre><code>// Set the controllerNamespace based on whether this is a console or web request
  if (Craft::$app-&gt;request-&gt;isConsoleRequest) {
      $this-&gt;controllerNamespace = 'modules\\fetchprofile\\console\\controllers';
  } else {
      $this-&gt;controllerNamespace = 'modules\\fetchprofile\\controllers';
  }
  
  parent::init();
  
  Event::on(
      Users::class, 
      Users::EVENT_AFTER_SAVE, 
       
      function (ModelEvent $event) {
          $user = $event-&gt;sender;        
          Craft::dd($user);
      }
  );
  </code></pre>
  <hr />
  <p>When dumping the $user object i get nothing. The ModelEvent function is never hit.
  What am I missing?</p>
  <h2>Update:
  SOLVED via <a href="https://craftcms.stackexchange.com/questions/26797/user-events-in-craft-3">User events in Craft 3</a></h2>
  <pre><code> Event::on(
              User::class,
              User::EVENT_AFTER_SAVE,
              function(ModelEvent $event) {
                  $user = $event-&gt;sender;        
                  Craft::dd($user);
              }
          );
  </code></pre>
  
Tags: <users><modules><events>
Title: Problem catching the after save user event in module
ThreadText: # Problem catching the after save user event in module
  
  (Asked by: username_0 on 2024-10-21)
  
  I have a module and I want to listen for the saving of a user profile in the front end. Module looks like this.
  
  ```
  use Craft;
  use yii\base\Event;
  use craft\events\UserEvent;
  use craft\fields\Users;
  use craft\events\ModelEvent;
  use yii\base\Module as BaseModule;
  
  ```
  
  My public init looks like this:
  
  public function init(): void
  {
  Craft::setAlias('@modules/fetchprofile', **DIR**);
  
  ```
  // Set the controllerNamespace based on whether this is a console or web request
  if (Craft::$app->request->isConsoleRequest) {
      $this->controllerNamespace = 'modules\\fetchprofile\\console\\controllers';
  } else {
      $this->controllerNamespace = 'modules\\fetchprofile\\controllers';
  }
  
  parent::init();
  
  Event::on(
      Users::class, 
      Users::EVENT_AFTER_SAVE, 
       
      function (ModelEvent $event) {
          $user = $event->sender;        
          Craft::dd($user);
      }
  );
  
  ```
  
  ---
  
  When dumping the $user object i get nothing. The ModelEvent function is never hit.
  What am I missing?
  
  ## Update: SOLVED via [User events in Craft 3](https://craftcms.stackexchange.com/questions/26797/user-events-in-craft-3)
  
  ```
   Event::on(
              User::class,
              User::EVENT_AFTER_SAVE,
              function(ModelEvent $event) {
                  $user = $event->sender;        
                  Craft::dd($user);
              }
          );
  
  ```
  
  **Tags:** users, modules, events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-10-22. Score: 1
  
  You're importing the wrong class for Users. Try `use craft\elements\User` instead of `use craft\fields\Users`. `elements\User` extends the base `elements` class which has the event you're trying to use - Here it is in the class reference with an example:
  
  <https://docs.craftcms.com/api/v5/craft-base-element.html#event-after-save>
  
  > **Comments:**
  > **username_0**: This doesn't work either. Produces error on the calling Event:    Event::on(Users::class, Users::EVENT_AFTER_SAVE,  Is there even a Users::EVENT_AFTER_SAVE? I swapped this for element but still the results are that the user data is saved but the module does not catch the event.  Looking here https://docs.craftcms.com/api/v5/craft-elements-user.html#events there is no user save event.  
  > **username_1**: It inherits from base\Element, so the event should still work. Note that the class is called `User` in the singular, not `Users`. Check for any other typos.  
  > **username_0**: Thx username_1 - still no dice  
  > **username_0**: Interesting - its saving and now I am finding user.errors is saying "unable to save your profile" - its coded in template. How can I get the console for user in frontend when they are not privileged i wonder.?  
  
  ---
  
  