Last active
December 27, 2015 14:39
-
-
Save modmedia/7342350 to your computer and use it in GitHub Desktop.
Create a Mura content node from a Mura form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Drop this into your site eventhandler.cfc ---> | |
<cffunction name="onAfterFormSubmitSave" output="true"> | |
<cfif $.event('formid') EQ '{ID of the Mura form}'> | |
<!--- Get the form result ---> | |
<cfset formBean = $.event().getValue('formresult')> | |
<!--- Get a new content bean ---> | |
<cfset cBean = application.contentManager.getBean()> | |
<!--- Set the new node attributes ---> | |
<cfset cBean.setSiteID($.event('siteid'))> | |
<cfset cBean.setType('Page')> | |
<cfset cBean.setSubType('mySubtype')> | |
<cfset cBean.setTitle(formBean.TITLE)> | |
<!--- Set any extended attributes ---> | |
<cfset cBean.setExtAttribute1(formBean.VALUE1)> | |
<cfset cBean.setExtAttribute2(formBean.VALUE2)> | |
<!--- if your form has a file in it, set it as the associated image ---> | |
<cfset cBean.setFileID(formBean.FILE_ATTACHMENT)> | |
<!--- Set the content ID of where you want this new node to live under ---> | |
<cfset cBean.setParentID('{content ID}')> | |
<!--- Set whether it's displayed, approved, nav, etc ---> | |
<cfset cBean.setApproved(1)> | |
<cfset cBean.setDisplay(1)> | |
<cfset cBean.save()> | |
</cfif> | |
</cffunction> |
Hi Matt,
i tried the above gist in my event handler and it was showing syntax error
this gives me a syntax error.
<cfif $.event('formid') EQ '{ID of the Mura form}'>
<!--- Get the form result struct--->
<cfset var formData= $.event('formresult')>
<cfset var cBean = $.getBean('content').set()( <!--- shows a syntax error at this line--->
type='Page',
subtype='mySubType',
title=formData.title,
extAttribute1=formData.value1,
extAttribute2=formData.value2,
fileid=formData.FILE_ATTACHMENT,
parentid='{content ID}',
approved=1,
display=1
).save() >
thanks
susan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's another way you can approach it. You also probably don't want to allows users to directly publish to your site from a form unless you they are trusted users. In that case you would set approved=0. That way the newly created content node will still need to be reviews and approved.