On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I think I know what's happening. The code above will fail if the Tvr doesn't exist already. Try this:

    $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)));
    
    if ($tvr) {
        $tvr->set('value', $qualificiation_areyou);
    
    } else {
        $tvr = $modx->newObject('modTemplateVarResource');
        $tvr->set('contentid', $projectFolderId);
        $tvr->set('tmplvarid', 32);
        $tvr->set('value', $qualificiation_areyou);
    }
        $tvr->save();
    
    
     
    $tvr = $modx->getObject('modTemplateVarResource', (array('contentid' => $projectFolderID, 'tmplvarid' => 33)));
    
    if ($tvr) {
        $tvr->set('value', $qualificiation_emailaddress);
    } else {
        $tvr = $modx->newObject('modTemplateVarResource');
        $tvr->set('contentid', $projectFolderID);
        $tvr->set('tmplvarid', 33);
        $tvr->set('value', $qualificiation_emailaddress);
    }
    $tvr->save();
     
    return true;


    I hope this is right. I'm on vacation in Paris and using a laptop with a very small screen, so it's hard to see typos.
    [ed. note: BobRay last edited this post 3 years, 4 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
    • Thanks Bob - really really really appreciate your assistance here! There was just one typo on the code a missing ")" after "$qualificiation_emailaddress" on 5th last line...

      Good news is that now does not make the submission fall over...

      Bad news is that it still does not set the value of the TV in resource 19.... have no idea why!
      • I do. $projectFolderId !== $projectFolderID. wink My mistake.
          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
        • Quote from: BobRay at Aug 31, 2016, 03:14 PM
          I do. $projectFolderId !== $projectFolderID. wink My mistake.

          Thanks Bob - where do I drop this line in?
          • That's not a new line. Just pointing out that the 'ID' in your $projectFolder variable in one place doesn't match the 'Id' in another.

            Change them all to 'ID' and you should be in business.

              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
            • Quote from: BobRay at Aug 31, 2016, 04:13 PM
              That's not a new line. Just pointing out that the 'ID' in your $projectFolder variable in one place doesn't match the 'Id' in another.

              Change them all to 'ID' and you should be in business.


              Ahh I see... wink Will give it a go...
              • Bob - YOU ARE A LEG END... once more you have saved my sanity... been bashing my head against this for days.... you have returned the smile to my face once more... I trust the sun is shining on you in Paris right now... now head out and enjoy a beer and a croissant! wink

                Cheers. dubbs.
                • Will do (though it's about 7:00 pm, so I think a beer and confit de canard -- a little late in the day for a croissant). Thanks for the kind words. smiley
                    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