We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34945
    • 15 Posts
    Hi all!
    Got a problem with xPDO in Revo 2.2RC1.
    I have created custom table with schema. Everything is right, it's not my first custom table in MODx. But when I create new object using modx->newObject(), it creates two records in DB instead of one, with the same contents.

    P.S. To do this I call a snippet as a FormIt hook, bur tracing shows that it implements once, but the newObject triggers twice.

    Thank you.
    • Unless you are calling save() twice after using newObject(), this should not happen. Sounds like you have an issue in your FormIt hook.
        • 34945
        • 15 Posts
        This is weird. So here's my FormIt hook's code:
        <?php
        
        $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/order_comments/';
        $modx->addPackage('order_comments',$base_path.'model/');
        
        $orderid = isset($orderid)?$orderid:0;
        if ($orderid == 0) {
            return false;
        }
        if ($modx->user->id == 0) {
            return false;
        }
        
        
        $comment = $modx->newObject('Order_comments', array(
            'orderid' => $orderid,
            'authorid' => $modx->user->id,
            'replyto' => 0,
            'createdon' => time(),
            'comment' => $hook->getValue('comment'),
        ));
        
        $comment->save();
        
        return true;
        
          • 34945
          • 15 Posts
          I've solved it by placing FormIt to another resource containing message like this "Thank you!" with the back link.
          Anyway, thanks, opengeek, you rule!