$tv->setValue($doc->get('id'), $value);
$tv->save();
}
}
$id = $doc->get('id');;
$modx->log(modX::LOG_LEVEL_ERROR, $id);
$url = $modx->makeUrl($id);
$modx->cacheManager->refresh();
$modx->sendRedirect($url);$modx->makeUrl(10);
<?php
$doc = $modx->getObject('Article',array('id'=>$hook->getValue('resource_id')));
$published = 1;
$date = date('Y-m-d H:i:s');
if (empty($doc)){
$doc = $modx->newObject('modDocument');
$doc->set('createdby', $modx->user->get('id'));
}
else{
$doc->set('editedby', $modx->user->get('id'));
}
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
if ($field !== 'spam'){
$doc->set($field, $value);
}
//we need to parse the title into the alias
if($field == 'pagetitle'){
//replace spaces with -
$alias = preg_replace('/[\' \']/' , '-' , $value);
//remove non alpha and a common injection string
$alias = preg_replace('/[^a-z0-9\.\x0B\-]/i' , '' , $alias);
//this is the standard revo regexp
// \0\x0B\t\n\r\f\a&=+%#<>"~:`@\?\[\]\{\}\|\^'\
}
}
$doc->set('parent', '2119');
$doc->set('alias', $alias);
$doc->set('template', '36');
$doc->set('published',$published);
$doc->set('publishedon', $date);
$doc->save();
foreach ($allFormFields as $field=>$value)
{
if ($tv = $modx->getObject('modTemplateVar', array ('name'=>$field)))
{
/* handles checkboxes & multiple selects elements */
if (is_array($value)) {
$featureInsert = array();
while (list($featureValue, $featureItem) = each($value)) {
$featureInsert[count($featureInsert)] = $featureItem;
}
$value = implode('||',$featureInsert);
}
$tv->setValue($doc->get('id'), $value);
$tv->save();
}
}
$id = $doc->get('id');
$modx->log(modX::LOG_LEVEL_ERROR, $id);
$url = $modx->makeUrl($id);
$modx->cacheManager->refresh();
$modx->sendRedirect($url);This question has been answered by multiple community members. See the first response.
$modx->reloadContext();
Try adding this after the save() if it's a new doc:
$modx->reloadContext();