Hello everyone!
I'm having a little issue with a Formit Hook that I made for a 3PC I'm working on. This might be a case of me just staring at it too long and missing something obvious (I'm hoping) so I figured I'd ask here for a new set of eyes.
The Formit call for adding items to my db is as follows:
[[!FormIt?
&hooks=`erHook,redirect`
&redirectTo=`[[*id]]`
&redirectParams=`{"success":"1"}`
&validate=`name:required,cat_id:required`
&submitVar=`addItem`
]]
The hook code is as follows:
<?php
$easyrestaurant = $modx->getService('easyrestaurant','Easyrestaurant',$modx->getOption('easyrestaurant.core_path',null,$modx->getOption('core_path').'components/easyrestaurant/').'model/easyrestaurant/',$scriptProperties);
if (!($easyrestaurant instanceof Easyrestaurant)) return '';
$edit = $hook->getValue('edit');
$itemid = $hook->getValue('itemid');
if($edit == 1) { $easyrestaurant_hook = $modx->getObject('erItems',$itemid); } else { $easyrestaurant_hook = $modx->newObject('erItems'); }
if (empty($easyrestaurant_hook)) {return 'I didn\'t get an object..';}
$easyrestaurant_hook->fromArray($scriptProperties['fields']);
$easyrestaurant_hook->save();
return true;
Editing items works great... Things are saving to the database successfully.. no problems there.
For some reason...I can't create new items though. The form is completely processed and returns with the success param, but no new items are in the database.
My initial inclination was that I was passing the edit field to the form accidentally and it was trying to edit an item that didn't exist, but I did some error checking there and it appears to be properly executing the "else" statement.
What are my tired eyes missing?
Thanks in advance!
-Jared
[ed. note: jaredloman last edited this post 13 years, 2 months ago.]