We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20471
    • 40 Posts
    I have a plugin that updates a mailing list on Campaign Monitor when a user is created/saved. It listens to the OnUserFormSave event, which works great if the user is updated from under Security > Manage users.

    However, if users update their own profile (User > Profile) I can't seem to trigger the plugin. I've tried listening to both OnUserFormSave and OnUserSave, but nothing happens.

    Any ideas? Should I listen to to some other event?
      • 20471
      • 40 Posts
      No one have any ideas here?
      • It doesn't appear to trigger any events, but it does allow for PostHooks.

        postHooks A comma-separated list of 'hooks', or Snippets, that will be executed after the user's profile is updated.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          I think you could create a postHook with this code:

          /* invoke OnUserFormSave event */
          /* I'm guessing at the user settings */
            $user = $scriptProperties['updateprofile.user'];
            $userId = $user->get('id');
          
          $modx->invokeEvent('OnUserFormSave',array(
              'mode' => modSystemEvent::MODE_UPD
              'user' => $user,
              'id' => $userId,
          ));
          



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 20471
            • 40 Posts
            Hi,

            I don't quite follow. BobRay, I assume your code triggers the OnUserFormSave event and passes along the correct variables? But how is this postHook triggered in the first place, i.e. how do I execute the code/snippet?
              • 3749
              • 24,544 Posts
              I assumed that you were using the UpdateProfile snippet. If so, you should be able to specify your snippet in the &postHooks property. If the user is updating their Profile in the Manager, OnUserFormSave should definitely be firing already. If not, it would be a bug.



              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 20471
                • 40 Posts
                Nope, I'm in the manager. And I have this plugin listening to OnUserFormSave:
                <?php
                require_once $modx->getOption('base_path') . 'assets/components/csapi/csrest_subscribers.php';
                
                $profile = $user->getOne('Profile');
                $wrap = new CS_REST_Subscribers('XXX', 'XXX');
                $result = $wrap->add(array(
                    'EmailAddress' => $profile->get('email'),
                    'Name' => $user->get('fullname'),
                    'Resubscribe' => false
                ));
                
                if(!$result->was_successful()) {
                    echo 'Failed with code '.$result->http_status_code."\n
                <pre>";
                    var_dump($result->response);
                    echo '</pre>';
                }


                If I update a user through menu Security > Manage Users it works just fine. And if I update myself through User > Profile nothing at all happens. I'm on MODx 2.2.5. [ed. note: mrtnrsl last edited this post 11 years, 6 months ago.]
                  • 3749
                  • 24,544 Posts
                  Ah, I forgot that menu existed. I looked at the code, and it saves just the profile without saving the user object or firing any events.

                  I would put in a feature request for an OnSaveUserProfile event or the equivalent.

                  If you feel daring, you could create such an event and put code to invoke it in the profile update processor.


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting