We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3689
    • 264 Posts
    If I have 2 parents.. "Active" site.com/active and "Inactive" site.com/inactive.. would it be possible to move a page from site.com/active/childpage02 to site.com/inactive/childpage02 if childpage02 has a TV Dropdown menu with 2 options Active and Inactive?

    I want the page to move to another parent depending on the TV option if thats possible
      • 3689
      • 264 Posts
      If not a TV is there another way to do this?
        • 3749
        • 24,544 Posts
        I don’t think a TV alone will do it. You’d need a plugin connected to OnBeforeDocFormSave that reads the TV and sets the parent.

        This should get you started: http://modxcms.com/forums/index.php?topic=27829.0

        I’m not positive, but I think you’ll want to change $_POST[’parent’] on the basis of the TV. This will happen just before the doc is saved so the parent should get set the way you want it.
          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
          • 3689
          • 264 Posts
          Quote from: BobRay at Jan 21, 2010, 10:27 PM

          I don’t think a TV alone will do it. You’d need a plugin connected to OnBeforeDocFormSave that reads the TV and sets the parent.

          This should get you started: http://modxcms.com/forums/index.php?topic=27829.0

          I’m not positive, but I think you’ll want to change $_POST[’parent’] on the basis of the TV. This will happen just before the doc is saved so the parent should get set the way you want it.


          little hard to understand for me but ill give it a try smiley what do you mean by Change $_POST[’parent’] on the basis of the TV?
            • 3749
            • 24,544 Posts
            I mean that in the plugin code, you’d have something like this (assuming your two parents have IDs 3 and 7):

            <?php
            $tv = $_POST['YourTvName'];
            
            If $tv == 'active' {
            
                $_POST['parent'] = 3;
            
            } else {
            
                $_POST['parent'] = 7;
            }
            
            Where YourTvName is the name of your TV.
            ?>


              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
              • 4172
              • 5,888 Posts
              so far I know, this does not work, because $_POST is stored in vars before OnBeforeDocFormSave and is no more called after that.
              what you can try instaed is change the parent after saving in OnDocFormSave with:

              <?php
              $parent=$_POST['tvYourTvName']=='active'?'3':'7';
              if ($parent !==$_POST['parent']){
                  $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$_POST['id']);
              }
              ?>


              [Edit]

              Its better to use $params[’id’] than $_POST[’id’], because on new documents there is no $_POST[’id’]
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 3749
                • 24,544 Posts
                Thanks for correcting that. I hadn’t tested it.
                  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
                  • 3689
                  • 264 Posts
                  Not sure if I was suppose to get part of the code from the post that was linked or just use the code pasted in here but I tried this

                  <?php
                  $parent=$_POST['status']=='active'?'4':'27';
                  if ($parent !==$_POST['parent']){
                      $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
                  }
                  ?>


                  is this correct?
                    • 3749
                    • 24,544 Posts
                    I think you need a tv prefix on ’status’ so it should be

                    $_POST['tvstatus']
                      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
                      • 3689
                      • 264 Posts
                      i tried adding "tvstatus" and it moved around some pages in my site tree but it didnt affect the pages on the main page.. here is an image of the site tree now



                      and here are is the tv


                      and the plugin:
                      <?php
                      $parent=$_POST['tvstatus']=='active'?'4':'27';
                      if ($parent !==$_POST['parent']){
                          $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
                      }
                      ?>