$prefix = 'xyz_';
$packagename = 'chroniclethis';
$classname = 'Grows';
$packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/');
$modelpath = $packagepath . 'model/';
$modx->addPackage($packagename, $modelpath, $prefix);
$dataobject = $modx->newObject($classname);
if (!is_object($dataobject) || !($dataobject instanceof xPDOObject)) {
$errorMsg = 'Failed to create object of type: ' . $classname;
$hook->addError('error_message', $errorMsg);
$modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Hook');
return false;
}
$formFields = $hook->getValues();
foreach ($formFields as $field => $value) {
if (!in_array($field, $removeFields)) {
if (in_array($field, $arrayFields)) {
switch ($arrayFormat) {
case 'json':
$value = json_encode($value);
break;
case 'csv' :
default :
$value = implode(',', $value);
break;
}
}
$dataobject->set($field, $value);
}
}
if (!$dataobject->save()) {
$errorMsg = 'Failed to save object of type: ' . $classname;
$hook->addError('error_message', $errorMsg);
$modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Hook');
return false;
}
return true;[[!FormIt? &hooks=`chronicleThis`]]
<form name="form" action="[[~[[*id]]]]" method="post" class="form">
<input type="hidden" name="owner_id" value="[[!+modx.user.id]]">
<li class="fieldOuterBox">
<label for="title" class="inputLabel">Title</label>
<input type="text" name="title" id="title" class="txtInput" value="[[!+fi.title]]" />
<span class="applyError">[[!+fi.error.title]]</span>
</li>
<li class="fieldOuterBox">
<label for="description" class="inputLabel">Description</label>
<textarea cols="40" rows="3" name="description" id="description" class="txtInput">[[!+fi.description]]</textarea>
<span class="applyError">[[!+fi.error.description]]</span>
</li>
<li class="fieldOuterBox">
<label for="image" class="inputLabel">Leader Image</label>
<a name="submit" class="btnSmall" onclick="leaderUploadPopup();" href>Select Image</a>
<br class="clear" />
<label for="image" class="inputLabel"> </label>
<img class="hidden">
<span class="applyError">[[!+fi.error.tags]]</span>
</li>
<li class="fieldOuterBox">
<label for="tags" class="inputLabel">Tags</label>
<input type="text" name="tags" id="tags" class="txtInput" value="[[!+fi.tags]]" />
<span class="applyError">[[!+fi.error.tags]]</span>
</li>
<li class="fieldOuterBox">
<label for="publish_on" class="inputLabel">Publish On (optional)</label>
<input type="text" name="publish_on" id="publish_on" class="txtInput" value="[[!+fi.publish_on]]" />
<span class="applyError">[[!+fi.error.publish_on]]</span>
</li>
<li class="fieldOuterBox">
<label for="publish" class="inputLabel"> </label>
<input type="checkbox" name="publish" id="publish" class="checkboxInput" value="1"/>
<span class="">Published</span>
<span class="applyError">[[!+fi.error.publish]]</span>
</li>
<li class="fieldOuterBox vWrapper">
<label for="submit" class="inputLabel"> </label>
<a name="submit" class="btnSmall" onclick="form.submit();" href>Save Grow</a>
</li>
</form>
<div class="cropBox">
<div>
<form>
</form>
</div>
</div>
<script>
$( "#publish_on" ).datepicker({
inline: true
});
</script>This question has been answered by aaronkent. See the first response.
foreach ($formFields as $field => $value) {
if (!in_array($field, $removeFields)) {
if (in_array($field, $arrayFields)) {foreach ($formFields as $field => $value) {
echo '<br><br>FIELD: ' . $field . ' -- VALUE: ' . $value;
if (!in_array($field, $removeFields)) {
echo '<br> ---- Passed Test 1';
if (in_array($field, $arrayFields)) {
echo '<br> ---- Passed Test 2';
foreach ($formFields as $field => $value) {
$modx->log(modX::LOG_LEVEL_ERROR, 'FIELD: ' . $field . ' -- VALUE: ' . $value, '', 'chronicleThis Hook');
if (!in_array($field, $removeFields)) {
$modx->log(modX::LOG_LEVEL_ERROR, '---- Passed Test 1', '', 'chronicleThis Hook');
if (in_array($field, $arrayFields)) {
$modx->log(modX::LOG_LEVEL_ERROR, '---- Passed Test 2', '', 'chronicleThis Hook');if (!is_object($dataobject) || !($dataobject instanceof xPDOObject)) {
$errorMsg = 'Failed to create object of type: ' . $classname;
$hook->addError('error_message', $errorMsg);
$modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Hook');
return false;
}My guess is that your problem is here and all fields are failing one of these tests, possibly due to the prefixes: