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
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);
-
☆ 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.
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.
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.
regarding permissions... what access policy needs to be set?
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.