Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active September 21, 2022 10:48
Show Gist options
  • Save matdave/71a9e1355e598946b470 to your computer and use it in GitHub Desktop.
Save matdave/71a9e1355e598946b470 to your computer and use it in GitHub Desktop.
<?php
$doc = $modx->newObject('modResource');
$doc->set('createdby', $modx->user->get('id'));
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
$doc->set($field, $value);
}
$doc->set('parent', '64');
$doc->set('alias', mktime());
$doc->set('template', '4');
$doc->set('published', '0');
$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();
}
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment