We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7045
    • 225 Posts
    I have a snippet I call from a postHook on the UpdateProfile page call. It sends an email to the website admin notifying them that one of their members has updated their profile and the member's info for id purposes. They now want the email to contain all the info that was changed in the member's profile, which makes sense.

    I will assume this is possible, but I just can't quite figure it out. Can someone nudge me in the correct direction?
      • 3749
      • 24,544 Posts
      The fields in the form should be available in the postHook with $hook->getValue().

      $userName = $hook->getValue('username');
      $email = $hook->getValue('email');
        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
        • 7045
        • 225 Posts
        Yes, the fields are available. I use some of them now for id purposes in the email, so the page admin knows who updated their profile. My question, how do I ONLY show the info that was changed/updated.

        If only the address was updated by the member in the UpdateProfile form, that is the only info I want to display in the email to the admin. Does that make sense?
          • 3749
          • 24,544 Posts
          Yes it does. I'm not sure there's an easy way and it might not be possible, because I suspect that the database has already been updated by the time your postHook runs.

          The way to find out would be to get the user Profile and check.

          $userObj = $modx->getObject('modUser', array ('username' => $userName));
          
          if ($userObj) {
             $profile = $userObject->getOne('Profile');
             $fields = $profile->toArray();
             var_dump($fields);
          }
          


          If those fields are different from the values you get with $hook->getValue(), you're in business.

          If not, the only thing I can think of is to put a snippet on the form page that does the above and saves the values to a $_SESSION variable or a file, then you could grab that and compare the values in your postHook.
            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
            • 3186 ☆ A M B ☆
            • 279 Posts
            To answer your question;
            You cannot see what is changed.. You can only get the whole record/object (like Bob showed) and pass that data into the email. So you only could show all instead of the changed data.

            You can work on a workaround for that, but that's up to you;
            What you can try is keep changed tracked in hidden input fields..
            You can have a hidden field like <input type="hidden" name="address_changed" value="no" />
            And then change it's value to "yes" with javascript/jquery when someone changes his address, and repeat this for all parts you want to track.

            Then you can build if else statements in your hook to figure that out.
              MODX Ambassador (NL) & Professional MODX developer
              Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
              MODX e-commerce solution SimpleCart
              • 7045
              • 225 Posts
              Thanks for the replies, Bob and bertoost. Ya, I should have figured it was harder than I was making it out to be in my head. I may try a workaround, if it's worth the time. Thanks again.
                • 3749
                • 24,544 Posts
                To expand on Bert's idea, you could have a hidden field for each input that holds the original value. Then in your postHook, you could compare that with the submitted value for each field.
                  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
                  • 7045
                  • 225 Posts
                  Ya, the "hidden field" idea is a really good one. Come to think of it, it actually makes what I was trying to do rather easy-ish. Thanks again, everyone.
                    • 3186 ☆ A M B ☆
                    • 279 Posts
                    NB: Consider one of the post is your answer ;-) then the topic will be marked as "answered" ;-)
                      MODX Ambassador (NL) & Professional MODX developer
                      Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                      MODX e-commerce solution SimpleCart