Form to Resource

Is there an accepted way for getting form submissions published directly as a resource?

I’m wanting to set up a very small neighbourhood site where people can send details of local tradespeople via a form which then creates an unpublished resource that I can then check and publish if acceptable.

Maybe Newspublisher or Formit2Resource

I think Formit2Resource looks the favourite simply because I’m familiar with Formit but do you think that’s the most up to date way of doing it?

Formit2Resource just uses $modx->newObject('modResource'); which is the normal way of creating a new object in MODx.
I’d use this snippet as a starting point and then customize it to your needs.

Alternatively you could call the “resource/create” processor $modx->runProcessor('resource/create',$values); if you have plugins that need to run on certain events (like ‘OnBeforeDocFormSave’ or ‘OnDocFormSave’) for this new resource.

1 Like

I think a big question is if you want anonymous users to be able to view and submit the form.

If not, NewsPublisher does everything you need it to do and is actively updated and maintained by Bob Ray. Is a bit of a set up as you would imagine, highly configurable, the docs are great, and he is responsive if you get stuck.

1 Like

If the form is publicly available you could reduce the security risk and the complexity by saving the Formit submissions, exporting them as .csv and using ImportX to create new resources from the rows in your (vetted) .csv file.

Thank you all. I’ve just got a basic version up and running using Formit with Formit2Resource. All seems to be working fine except the form redirect which I will sort out in due course.

The whole site will be password protected - just for use in the local community so I’m confident security will be fine.

Can’t work out why the redirect isn’t working. Saving the form and creating the resource is working, just not the redirect…

[[!FormIt?
    &hooks=`spam,email,FormItSaveForm,formit2resource,redirect`
    &preHooks=`resource2formit`
    &resource2formitfields=`pagetitle,alias,longtitle,description,introtext,content`
    &emailTpl=`candidate_email.chunk`
    &emailFrom=`[[$mainemail]]`
    &emailTo=`[[$mainemail]]`
    &redirectTo=`2`
    &submitVar=`Canreg`
    &emailUseFieldForSubject=`0`
    &emailSubject=`Directory Submission`
    &validate=`nospam:blank,parent:required,firstname:required,house:required,street:required,pagetitle:required,longtitle:required,description:required,content:required,
    email:email:required`]]

Does your custom hook snippet “formit2resource” return true at the end?

...
return true;
1 Like

Yes it does but I’m wondering - is there a definite place to get those snippets from. I found them in previous forum posts.

Aha! the snippet resource2formit did not end like that but it now does and it works. Thank you so much. I would never have spotted that!