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);
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 */