We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45950
    • 40 Posts
    I've created the custom table and a form via formit2db to populate the table. now what I would like to do with a formit hook is to generate a page in an unpublished state from a tpl that has the placeholders to populate the page from the row just created by the form submit.

    Somewhere I think I read on how to do this but can't remember where it was.

    Thanks in advance for your help
      • 3749
      • 24,544 Posts
      You'll want some sanity checks, but this should get you started (you'll have to use the names of the actual placeholders):


      $fields = array();
      $fields['pagetitle'] = $hook->getValue('pagetitle');
      $fields['alias'] = $hook->getValue('alias');
      $fields['content'] = $hook->getValue('content');
      $fields['published'] = false;
      
      $modx->runProcessor('resource/create', $fields);
      
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Doesn't runProcessor only work if the user is logged in with the appropriate permissions? If I understand correctly, this particular application will be based on web users; I believe the page will be created on successful registration.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          The user has to have permission to create a resource. I assumed that this all would happen on the page with the ConfirmRegister snippet, in which case the person would be logged in.

          Creating new directories and resources for unconfirmed users (who could be bots) seems questionable to me.
            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
            • 45950
            • 40 Posts
            this is in fact for a logged in user...however it is after the user has registered and confirmed and creates a profile via a form via their user management page links.
              • 45950
              • 40 Posts
              regarding permissions... what access policy needs to be set?
                • 3749
                • 24,544 Posts
                For a new resource, the user needs the new_document permission. To edit an existing resource the user need the save_document permission.

                If any of the resources will be at the root of the tree, the user needs new_document_in_root permission.

                The Content Editor policy has the first two, but not the last one, so it would be a good choice if no resources will be created in the root. The policy would be attached to a Context Access ACL entry for the user's user group, with a context of 'web'.

                If the resources are in a protected resource group, you'll also need a Resource Group Access ACL entry for the user group with a context of 'web'. In this case, I'd recommend a custom policy based on the Resource policy, but with any permissions you don't want them to have unchecked.

                If there are permissions on the Content Editor policy you don't want them to have, I'd recommend duplicating it, unchecking them on the duplicate policy, and using the duplicate policy in the Context Access ACL entry.
                  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