<![CDATA[ SOLVED: Custom Formit Hook - My Forums]]> https://forums.modx.com/thread/?thread=71441 <![CDATA[Re: SOLVED: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-560468 raffenberg Aug 07, 2018, 01:35 PM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-560468 <![CDATA[Re: SOLVED: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-559042 ]]> jeffmiranda Jun 12, 2018, 07:47 PM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-559042 <![CDATA[Re: SOLVED: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-404783
I've been struggling with this problem for months now and finally solved it!

Thanks a million!]]>
rover87 Dec 25, 2011, 06:19 PM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-404783
<![CDATA[Re: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398625
When creating a Formit hook that calls a custom class, there is an issue with the model path used in your component matching up with Formits.

Essentially, (as Bert explained it) if the name matches, Formit will use it's own model path as opposed to your scripts model path. So simply changing it to "modelsPath" fixed the issue.

Again, my sincerest thanks to Bert Oost for his advice in this situation.

-Jared]]>
jaredloman Nov 01, 2011, 02:01 AM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398625
<![CDATA[Re: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398621
[2011-10-31 21:51:13] (ERROR @ /HMB/index.php) Could not load class: erItems from mysql.eritems.

Looking into this error... I changed all of my class names to lowercase. Unfortunately this didn't help.. Still getting the same error but with the lower case class name.
[2011-10-31 22:07:52] (ERROR @ /HMB/index.php) Could not load class: eritems from mysql.eritems.
]]>
jaredloman Oct 31, 2011, 11:53 PM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398621
<![CDATA[SOLVED: Custom Formit Hook]]> https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398610
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]]>
jaredloman Oct 31, 2011, 10:41 PM https://forums.modx.com/thread/71441/custom-formit-hook#dis-post-398610