We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    I am attempting to set the values of some TVs via a post or pre hook on a login register call - but i get server error page when it processes the snippet... Can anyone tell me why this is not working?

    // get values from qualification, project and account forms
    
    $qualificiation_areyou = $hook->getValue('qualificiation_areyou');
    $qualificiation_emailaddress = $hook->getValue('qualificiation_emailaddress');
    
    
    // set TVs to values as per form data
    
    $projectFolderID = 19;
    $doc = $modx->getObject('modDocument',$projectFolderID);
    
    $doc->setTVValue(32, $qualificiation_areyou);
    $doc->setTVValue(33, $qualificiation_emailaddress);
    
    
    return true;
    


    So, I am getting the form field values of fields "qualificiation_areyou" and "qualificiation_emailaddress" in the snippet, then defining the modx resource I want to set the TVs on - e.g. id=19, then setting the TVs (e.g. 32 and 33) to the values of the form fields "qualificiation_areyou" and "qualificiation_emailaddress" respectively...

    Why is this not working??
      • 3749
      • 24,544 Posts
      It might work with $doc->save() at the end.

      Another (faster) way to go, assuming that you can use the raw values of the TVs, is to set the values directly. There's no need to get the resource object itself unless you need it for something else:


      $qualificiation_areyou = $hook->getValue('qualificiation_areyou');
      $qualificiation_emailaddress = $hook->getValue('qualificiation_emailaddress');
       
       
      // set TVs to values as per form data
       $projectFolderID = 19;
      $tvr = $modx->getObject('modTemplateVarResource', (array('contentid' => $projectFolderID, 'tmplvarid' => 32)));
      $tvr->set('value', $qualificiation_areyou);
      $tvr->save();
      
      $tvr = $modx->getObject('modTemplateVarResource', (array('contentid' => $projectFolderID, 'tmplvarid' => 33)));
      $tvr->set('value', $qualificiation_emailaddress);
      $tvr->save();
      
      return true;
      [ed. note: BobRay last edited this post 7 years, 7 months ago.]
        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
        • 8168
        • 1,118 Posts
        Thanks Bob - but I still get an error page when I hit the submit button and the snippet processes... can the login register code not allow setting of TVs??
          • 3749
          • 24,544 Posts
          I can't think of any reason why it wouldn't as long as you use a postHook and return true.

          Did you try the code in the message above?
            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
            • 8168
            • 1,118 Posts
            Yep... Its very odd... I have a 2nd postHook running - could they interfere with each other perhaps? The other is sending some emails once the form is submitted.. better to combine into 1 snippet perhaps?

            Is there a way to debug snippet errors?
              • 8168
              • 1,118 Posts
              Not the other snippet messing up this one, as tested without the other one being called and still errors...
                • 3749
                • 24,544 Posts
                Are you sure the getValue() calls are getting the correct values?
                  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
                  • 8168
                  • 1,118 Posts
                  Yep - but to eliminate that as a potential issue - I can remove them from the code, and then also hard code the new TV Value as below... this should work yeh?

                  $qualificiation_areyou = 'Monkey';
                  $qualificiation_emailaddress = 'Chicken';
                    
                    
                  // set TVs to values as per form data
                  $projectFolderID = 19;
                  $tvr = $modx->getObject('modTemplateVarResource', (array('contentid' => $projectFolderID, 'tmplvarid' => 32)));
                  $tvr->set('value', $qualificiation_areyou);
                  $tvr->save();
                   
                  $tvr = $modx->getObject('modTemplateVarResource', (array('contentid' => $projectFolderID, 'tmplvarid' => 33)));
                  $tvr->set('value', $qualificiation_emailaddress);
                  $tvr->save();
                   
                  return true;
                  
                    • 8168
                    • 1,118 Posts
                    RE: above - still get a blank white screen after submit... something not working...

                    It's very odd as on a Formit form, in the same site, I have the same thing working just fine...
                      • 8168
                      • 1,118 Posts
                      Would it work better as a plugin maybe? No idea how to do that... just trying to solve this one!!!