We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7858
    • 97 Posts
    Hi, I need to send an Email, if some specific TV value was changed in manager.

    I'm trying to write a Plugin, that handles OnDocFormPrerender and OnDocFormSave events. But I need to compare TV value on theese to events. How can I set something like global var with tv value OnDocFormPrerender and then compare it to the value of same var OnDocFormSave.

    I don't ask for a whole code, but I cann't get how to store initial value and than load it on doc save.

    Thx.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could save it to a SESSION value on render, then compare it to the SESSION value on save.
        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
        • 7858
        • 97 Posts
        sottwell

        I have tried with a SESSION before opening this thread

        $_SESSION['loadtitle'] = $tvvalue;
        
        $prevtvvalue = $_SESSION['loadtitle'];


        but that didn't work for me. What am I doing wrong?

        EDIT: I've got it work, I had misspelled somewhere in my code. [ed. note: dopeless last edited this post 13 years, 1 month ago.]
          • 3749
          • 24,544 Posts
          You can actually do all in OnBeforeDocFormSave with no $_SESSION variable. You can get the new value from the $scriptProperties array and compare that value with old value you get from $resource->getTVValue().

          The new values are in:

          $scriptProperties['data']['tvs'];


          The old value is in:
          $resource->getTVValue('MyTV');


          CacheMaster used to have code to do exactly that, but it no longer does the check. You can see the code in the checkTvs() method of the initial commit at GitHub: https://raw.github.com/BobRay/CacheMaster/ac1528e391bb68e0dbd0e420e89197955a8a2d60/core/components/cachemaster/elements/plugins/cachemaster.plugin.php
            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
            • 7858
            • 97 Posts
            BobRay
            It's sure a better way, then SESSION... thx.


            hm... how do I get needed value from $scriptProperties['data']['tvs'];? [ed. note: dopeless last edited this post 13 years, 1 month ago.]
              • 3749
              • 24,544 Posts
              I'm not positive, since I was checking them all.

              Now that I look at the code, I think the values are in the ['data'] array, not ['data']['tvs'] (though if ['data']['tvs'] is set, it tells you that there are TVS).

              I think they are in the ['data'] array as 'tv#' => 'value'

              where # is the id of the TV.

              To be sure, you could dump the array to the error log. I think it would be:

              $msg = print_r($scriptProperties['data'], true);
              $modx->log(MODX::LOG_LEVEL_ERROR, $msg );
              


                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