We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51216
    • 35 Posts
    Is there a way to insert the database ID into the emails via Formit using the FormSave hook?

    I would like to do something like:

    &emailSubject=`[[++site_name]] Website Enquiry | Reference - [[database ID]]`
      • 3749
      • 24,544 Posts
      Sorry, if I'm being dense, but I don't know what you mean by 'database ID'. The name of the DB? The ID used to log in to the DB? The DB's name? The current user's user ID? The email recipient's user ID?
        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
        • 51216
        • 35 Posts
        You are most certainly not being dense. I, on the on the other hand, am pretty dense when it comes to this kind of stuff. So please bear with me.

        To make one correction I meant the FormItSaveForm hook not the FormSave hook.

        To clarify about the 'database ID' what I meant was the id used to log in to the DB (the incremented id number).
        In the table 'modx_formit_forms' to be specific.

        Hope that makes sense
          • 3749
          • 24,544 Posts
          Ah, that's a new feature. I couldn't find any docs for it anywhere.

          Looking at the code, I couldn't really tell what it's supposed to be used for, so the following is pure speculation on my part.

          It looks like if you add a hidden input field named savedFormHashKey, the FormItSaveForm hook snippet will create a hash (id) and put it's value in a hook variable called savedFormHashKey. I think later hooks in the chain can then get the hash with $hook->getValue('savedFormHashKey'). As far as I can tell, the autoincrement ID field is never used for anything. Form data is retrieved from the table by the hash value.

          If the form's contents don't need to be ultra-secure, FormIt2DB might be an easier way to go.

          Take my advice with a grain of salt. I never use any part of the FormIt package and I've never used FormIt2DB. I generally roll my own form snippets so I can step through them in my debugger.
            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
            • 50816
            • 12 Posts
            Hey scoder,

            I don't know, if you solved your problem, but I just discovered a mixin which is not really documented somewhere in the modx docs. When you use it as a preHook, you can "preload" the data of a submitted form and display it in your form fields. You can read more about it in the pull request on github: https://github.com/Sterc/FormIt/pull/94.

            Example how to use:
            $formItScriptProperties['hooks'] = 'FormItSaveForm';
            $formItScriptProperties['preHooks'] = 'FormItLoadSavedForm';
            $formItScriptProperties['updateSavedForm'] = 'true';
            $formItScriptProperties['savedFormHashKeyField'] = 'urlparameter';
            
            $modx->runSnippet('FormIt', $formItScriptProperties);
            
            // open in browser
            http://www.urltoyourform.com/?urlparameter=6e711846b4e8a15a4de352d7801933c9