We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Not sure where to post this so move if needed... grin

    Hello, I have a plugin that creates a list of documents when a user signs up with loginpe but so far I have it only working with one usergroup. My aim is to have 2 different forms that 1 type of user can register with and another form that another type of user registers. Basically I want register1 to have 3 docs added and register2 to have 4 docs created. I have the plugin working with how many docs and what their content is but I want a switch statement to say form1 has been filled out so you get 3 docs, if form2 you get 4 docs. Not I know in theory what I need, I’m just not a programmer at all so it’s been hard for me to get this working. After days of reading and searching I still am not any further forward. Is there anyone able to give me a simple switch statement that would cover what I need?

      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 3749
      • 24,544 Posts
      If I’m understanding you correctly, you have two registration pages and want your plugin to behave differently depending on which page is up when the plugin is activated.

      You should be able to get the current page ID with $modx->documentIdentifier, so the simplest solution would be to put an if statement in your plugin:

      if ($modx->documentIdentifier == 5) {
      
           //  create your docs here
      
      } elseif ($modx->documentIdentifier == 6) {
      
          //  create your other docs here
      
      } else {
      
           echo "Error - unknown page";
      }


      Replace 5 and 6 with the document IDs of your two registration pages.

      
      Or, if you'd rather use a switch statement:
      
      switch ($modx->documentIdentifier) {
          case 5:
              // create documents
             break;
      
          case 6:
              //create documents
              break;
      
          default:
              echo "Unknown document";
             break;
      
      }
        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
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Thank you so much! Seem like it’s worked for what I need it to.



        Re: Plugin Switch Statement
        « Reply #1 on: Today at 12:23 PM »
        Reply with quoteQuote
        If I’m understanding you correctly, you have two registration pages and want your plugin to behave differently depending on which page is up when the plugin is activated.

        You should be able to get the current page ID with $modx->documentIdentifier, so the simplest solution would be to put an if statement in your plugin:

        Code:

        if ($modx->documentIdentifier == 5) {

        // create your docs here

        } elseif $modx->documentIdentifier == 6) {

        // create your other docs here

        } else {

        echo "Error - unknown page";
        }


        Replace 5 and 6 with the document IDs of your two registration pages.

        Code:


        Or, if you’d rather use a switch statement:

        switch ($modx->documentIdentifier) {
        case 5:
        // create documents
        break;

        case 6:
        //create documents
        break;

        default:
        echo "Unknown document";
        break;

        }

        This worked as the other one didn’t... This opens up all sorts of ideas for me now since the switch statement works with forms. grin
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 3749
          • 24,544 Posts
          Glad it worked. The first version would have worked as well if not for the (oops) mismatched parentheses in the elseif statement (fixed my post above). embarrassed

          They do the same thing, although the switch statement should be a little bit faster since the $modx->documentIdentifier is only evaluated once.
            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
            • 25551 ☆ A M B ☆
            • 1,231 Posts
            HAHA I no wonder it didn’t work, though it didn’t throw up an error on my page... it just didn’t activate the plugin! Anyway the switch is what I went with and it’s a bit simpler for myself to understand as well. Thanks again.
              Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
              AugmentBLU - MODX Partner

              BLUcart - MODX Revolution E-Commerce & Shopping Cart
              • 3749
              • 24,544 Posts
              Quote from: rossco at Sep 20, 2008, 03:00 AM

              HAHA I no wonder it didn’t work, though it didn’t throw up an error on my page... it just didn’t activate the plugin!  Anyway the switch is what I went with and it’s a bit simpler for myself to understand as well.  Thanks again.

              The thing to remember for a switch statement is the "break;" that ends each case. It’s a common mistake to forget the "break;" and wonder why the code isn’t working right.
                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