We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37859
    • 34 Posts
    Bob, I want the pagetitle to be altered based on the values that the user entered in the TV's.
    I was thinking that it must be done before saving the resource, like you suggest.
    But I've never written any plugin because I'm fairly new to modx revolution, so this is a difficulty for me.
    Can you please show me an example of such a plugin ?
    • discuss.answer
      • 3749
      • 24,544 Posts
      I'm guessing somewhat, but it should look pretty much like this (connected to OnDocFormSave). This assumes that the IDs of your two TVs are 12 and 22, so change those numbers to the actual TV IDs. This would be the entire plugin code:

      $value1 = $resource->getTVValue(12);
      $value2 = $resource->getTVValue(22);
      $resource->set('pagetitle', $value1 . $value2);
      $resource->save();
      return '';
      


      There are some ways to speed this up, but since it won't affect page-load speeds, they're probably not worth the trouble.
        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
        • 42562
        • 1,145 Posts
        Quote from: bendy4 at Jul 10, 2015, 07:07 AM
        I want the pagetitle to be altered based on the values that the user entered in the TV's.

        @BobRay, in his case, do the TVs have values already in the MODx DB, or are they going to have their value for the first time when he submits the form?
        Or upon saving, are the TVs registered before the pagetitle? - I am not even sure I am making sense to myself.
        I am in wonder how MODx works here.
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 3749
          • 24,544 Posts
          It's a good question. That's why I used OnDocFormSave rather then OnBeforeDocFormSave. They should be there by the time that event fires (hopefully). OnBeforeDocFormSave might work, but I think probably not.

          NewsPublisher sends the TV values to the resource/create processor, but unfortunately, AFAIK, they're not in the array sent to the System Events, so you have to get them from the DB.
            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
            • 37859
            • 34 Posts
            Thanks guys, got it working !
            Great to get this help as a novice here.