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

    I’m writing a plugin that does inserts and updates on a db table that triggers on OnDocFormSave, but I would also like the same plugin to handle OnDocFormDelete so I can also delete rows from the table.

    I don’t particularly want to create a separate plugin for this event. Is there a variable or something that is accessible from the plugin that will tell me the name of the current event being triggered?

    Thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Use a switch structure, and select both events when configuring the plugin.
        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
        • 30223
        • 1,010 Posts
        Here’s a common structure for plugins:

        <?php
        $evt =  &$modx->Event;
        
        switch ($evt->name) {
            case 'OnDocFormSave'  :
                //do whatever it takes
                break;
        
            case 'OnDocFormDelete ' :
                //guess what,... more code
                break;
        
        } 
        //end plugin code
        ?>
        
          • 686
          • 24 Posts
          Thats exactly what I need TobyL.

          Thanks a lot.