We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47742
    • 13 Posts
    I have a TV set up in a document that is an input of text. It is used to hold the contents of data collected from a snippet. When I echo the before value and after value, it is correct. But, when I open the document, it is not saved. Please help! Here is my code:

    $doc = $modx->getObject('modDocument',35);
    $tv = $modx->getObject('modTemplateVar', array('name'=>'tvName'));
    $before = $tv->getValue($doc);
    $newValue = "new Text";
    $tv->setValue($redirectPg, $newValue);
    $tv->save();
    $doc->save();

    $after = $tv->getValue($doc);
    echo('Before='.$before.' After='.$after);
      • 3749
      • 24,544 Posts
      It doesn't appear that you're setting the value of $redirectPg. You could do this instead:

      $tv->setValue(35, $newValue);


      You can also skip getting the TV and just do this:

      $doc = $modx->getObject('modDocument',35);
      $newValue = "new Text";
      $doc->setTVValue(12, $newValue); /* replace 12 with the ID of the TV */
      /* no need to save anything here */
        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