We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    try this one:
    <?php
    $parents['Active']='4';
    $parents['Pending']='34';
    $parents['Sold']='27';
    
    if (array_key_exists($_POST['tvstatus'],$parents){
    $parent=$parents[$_POST['tvstatus']];
    if ($parent !==$_POST['parent']){
        $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
    }
    }



    ?>
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 3689
      • 264 Posts
      <?php
      $parents['Active']='4';
      $parents['Pending']='34';
      $parents['Sold']='27';
      
      if (array_key_exists($_POST['tvstatus'],$parents){
      $parent=$parents[$_POST['tvstatus']];
      if ($parent !==$_POST['parent']){
          $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
      }
      }
      ?>


      this doesnt work for me 4 some reason.. i tried all 3 choices and nothin moves.. is there somethin im not doin right? does the name of the plugin matter?
        • 3749
        • 24,544 Posts
        This line is missing a closing ’)’

        if (array_key_exists($_POST['tvstatus'],$parents){


        Should be:

        if (array_key_exists($_POST['tvstatus'],$parents)){


        Make sure the name of the TV ’status’ or ’Status’ or ’Property Status’ matches the name in the code (’tvstatus’, ’tvStatus’, or ’tvProperty Status’).

        BTW, if you make your TV input value:

        Active==4||Pending==34||Sold==27


        The user will see what you have now but the retrieved value will be the actual ID. That would make the code simpler and a little faster.

        <?php
        
        if (in_array($_POST['tvstatus'],array('4','34','27'))){
           $parent=$_POST['tvstatus'];
           if ($parent !==$_POST['parent']){
              $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
           }
        }
        ?>
          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
          its hard for me to figure out whats wrong since i dont understand the php but ill post as much as i can..

          Plugin
          Plugin Name: switchParent
          Configuration Settings: None
          System Events: OnDocFormSave
          Plugin Code:
          <?php
          
          if (in_array($_POST['tvstatus'],array('4','34','27'))){
             $parent=$_POST['tvstatus'];
             if ($parent !==$_POST['parent']){
                $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
             }
          }
          ?>


          Template Variable
          TV Name: status
          Input Type: DropDown List Menu
          Input Option Values: Active||Pending||Sold (also tried Active==4||Pending==34||Sold==27)
          Default Value: Active (also tried Active==4)

          Sorry it doesnt seem to be workin.. not sure whats goin on.. could anythin else be causing a problem?
            • 3749
            • 24,544 Posts
            I think OnDocFormSave is invoked *after* the doc is saved to the DB. Try using OnBeforeDocFormSave.
              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
              • 26931
              • 2,314 Posts
              hi there,

              just tried it and didn’t succeed. afaik plugins shouldn’t be wrapped in <?php ?>, but didn’t work nonetheless
                • 3689
                • 264 Posts
                OnBeforeDocFormSave didnt work either.. is there anythin else i can try or is this not possible to do?
                  • 3749
                  • 24,544 Posts
                  It’s definitely doable. I know there’s a snippet that sets the document’s permissions to match those of the parent during OnDocFormSave and it must use a similar process.

                  I can think of some clunky ways of doing it, but hopefully, someone will see what we’re doing wrong and chime in.

                    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
                    ok, key ist not tvstatus but tvid_In_site_tmplvars
                    tested it with onDocFormSave and it worked with this code:

                    <?php//remove this line, only for sytnax-highlighting
                    $rs=$modx->db->select('id',$modx->getFullTablename('site_tmplvars'),'name="status"');
                    $row=$modx->db->getRow($rs);
                    //$modx->logEvent('1','1',print_r($_POST['tv'.$row['id']],true));
                    if (in_array($_POST['tv'.$row['id']],array('4','34','27'))){
                       $parent=$_POST['tv'.$row['id']];
                       if ($parent !==$_POST['parent']){
                          $modx->db->update(array('parent'=>$parent),$modx->getFullTablename('site_content'),'id='.$params['id']);
                       }
                    }
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 26931
                      • 2,314 Posts
                      ok, key ist not tvstatus but tvid_In_site_tmplvars
                      tested it with onDocFormSave and it worked with this code:
                      thanks Bruno smiley this is working great!