We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40097
    • 19 Posts
    Hi all, and thanks for all your contributions to this wonderful community.

    I'm trying to write a snippet to be used with formit as a hook to save the record to the database, and also a second formit hook snippet to update the record. I'm having an issue getting modx to save my snipplet, I'm not sure why but I have identified the line that modx seems to freak out about and refuses to save the snippet.. There are no logs in the modx error logs.

    <?php
    
    global $modx;
    $emailaddress = $hook->getValue('emailaddress');
    
    $sql = "INSERT INTO websignups ( emailaddress, sourceid) VALUES ('$emailaddress', 0)";
    $stmt = $this->modx->prepare($sql);
    $stmt->execute(); // <<<<< this is the line, that when included the snippet will not save.
    return true;
    


    Any ideas why this line is a problem?
    Thanks for your assistance.
      • 3749
      • 24,544 Posts
      You might take a look at the formit2db extra. http://modx.com/extras/package/formit2db
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 40097
        • 19 Posts
        Quote from: BobRay at Sep 16, 2013, 02:46 AM
        You might take a look at the formit2db extra. http://modx.com/extras/package/formit2db

        Thanks I saw that package, and it doesn't seem to work, as the thread that is mentioned on the package ends with a issues, that I too am faced with.

        My code
        [[!FormIt? 
          &hooks=`spam,email,formit2db,redirect` 
          &preHooks=`db2formit`
          &redirectTo=`10` 
          &validate=`emailaddress:required:email` 
          &spamEmailFields = `emailaddress`
          &emailTpl=`ConfirmEmailWithLink`
          &emailSubject=`Please Confirm Your Email Address`
          &emailTo=`[[+emailaddress]]`
          &emailReplyTo=`[email protected]`
          &prefix=`modx_custom_`
          &packagename=`emaillistsignup`
          &tablename=`websignups`
        ]]


        And the errors from the modx error logs are the same as the other users on the formit2DB thread.

        [2013-09-16 15:09:59] (ERROR @ /index.php) Path specified for package emaillistsignup is not a valid or accessible directory: /home/itract/public_html/core/components/emaillistsignup/model/
        [2013-09-16 15:10:00] (ERROR @ /index.php) Path specified for package emaillistsignup is not a valid or accessible directory: /home/itract/public_html/core/components/emaillistsignup/model/
        [2013-09-16 15:10:00] (ERROR @ /index.php) No class specified for loadClass
        [2013-09-16 15:10:01] (ERROR @ /index.php) Path specified for package emaillistsignup is not a valid or accessible directory: /home/itract/public_html/core/components/emaillistsignup/model/

        I even created the folder emaillistsignup in the components subfolder. set perms to 777.. still nothing....

        ah..kind of why I just wanted to write directly to the sql db... this is way more code and time, for such a simple task.