We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3493
    • 66 Posts
    Hi guys!

    First of all, thanks for this great framework. I love it!

    Here’s a question for you...
    I’m working on a function that automaticly adds a new topic to my Invision Power Board along with the new document I’m creating in MODx. I want it to be controlled using a TV checkbox, saying something like "Create forum topic". When it’s activated and I click Save, I need this function to check if I did activate the checkbox or not, and run the neccessary script if it has to.

    Now, where would I place this function? I’d love to add it as a module/plugin, instead of altering the core code, so it can easily be installed by other MODx members when I distribute it here after it’s done. How can I achieve this? Is there a way to make this a module/plugin, and easily have it "listen to" the template variable?

    I’ve already written the neccessary topic adding PHP function and tested it. It’s using IPB-SDK classes for simple programming, instead of writing full advanced functions that takes ages to complete.

    I think this would be a very important add-on to an already rich CMS, and I feel it’s important both for me and for other MODx users to have this function available for downloading. I’d be more than happy to program it, but I can’t do it without any help. Please share your knowledge with me for a brief moment, friends! Thanks smiley
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It would be done as a plugin, using "onDocFormSave". I can’t say any more than that; I’ve never done anything like that, but it should do the job.
        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
        • 3493
        • 66 Posts
        Okay! Thanks, Susan! smiley

        So, one problem down, one to go...
        How do I make the plugin check the TV value?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          As I said, I’ve never done this myself, but looking at another plugin that works with documents, I see this code:
          global $content;
          $e = &$modx->Event;
          
          switch($e->name) {
            case 'OnDocFormPrerender':
              if(($_REQUEST['pid'] > 0) && ($id == 0)) {
                if($parent = $modx->getPageInfo($_REQUEST['pid'],0,'template')) {
                  $content['template'] = $parent['template'];
                }
              }
              break;
          
            default:
              return;
              break;
          }
          

          So I would imaging that if you change the case to onDocFormSave, you could add your code to check which group the TV (see this post http://modxcms.com/forums/index.php/topic,6483.msg45503.html#msg45503) and do whatever needs to be done.
            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
            • 3493
            • 66 Posts
            Ah, Great! laugh
            I think this might have been exactly what I need. I’ll have a closer look at it soon. Now I have to get my butt to bed, so I’ll be able to go rafting tomorrow.

            Thanks for your help, Susan! You’re a very important resource to this community!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Thanks, but I’m not really so big by myself, I stand on the shoulders of giants.
                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