We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14951
    • 151 Posts
    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 12 years, 5 months ago.]
      • 14951
      • 151 Posts
      Update: I'm getting the following in my error log
      [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.
      [ed. note: jaredloman last edited this post 12 years, 5 months ago.]
        • 14951
        • 151 Posts
        With a million thanks to SimpleCart developer Bert Oost for his advice, this problem is resolved. In case someone else runs into this issue in the future, here was the problem (which I would have never found).

        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
          • 25586
          • 105 Posts
          THANK YOU SO MUCH!

          I've been struggling with this problem for months now and finally solved it!

          Thanks a million!
            • 37031
            • 93 Posts
            +1 on this! Thanks for posting the solution smiley
              • 33962
              • 13 Posts
              THANK YOU SO MUCH!