Skip to content

Instantly share code, notes, and snippets.

@jbuda
Created March 19, 2013 12:47
Show Gist options
  • Save jbuda/5195810 to your computer and use it in GitHub Desktop.
Save jbuda/5195810 to your computer and use it in GitHub Desktop.
Pre-populating MuraCMS form field within the ContentRenderer.cfc
<cffunction name="dspObjects" access="public" output="false" returntype="string">
<cfargument name="columnID" required="yes" type="numeric" default="1">
<cfargument name="ContentHistID" required="yes" type="string" default="#event.getValue('contentBean').getcontenthistid()#">
<cfset var rsObjects="">
<!--- get the string from super --->
<cfset var theRegion=trim(super.dspObjects(arguments.columnID,arguments.ContentHistID)) />
<!--- using the returned string look for any form to pre-polulate --->
<cfset bodystr = theRegion />
<cfset bodystrRes = refindnocase(">form.*?(name)*<",bodystr,1,true) />
<!--- ensure a form is present before continuing --->
<cfif bodystrRes.len[1] gt 0>
<cfset formstr = mid(bodystr,bodystrRes.pos[1],bodystrRes.len[1]) />
<cfset formstrRes = refindnocase('(name=\")(\w*)(\")',formstr,1,true) />
<!--- get the name of the form to check for pre-population --->
<cfset formname = mid(formstr,formstrRes.pos[3],formstrRes.len[3]) />
<cfswitch expression="#formname#">
<cfcase value="testForm">
<cfset tech = rereplacenocase(request.technology,"-"," ","ALL") />
<!--- replace the form field value with the technology in the url --->
<cfset theRegion = rereplacenocase(theRegion,'name="technology"','name="technology" value="#tech#"',"ALL") />
</cfcase>
</cfswitch>
</cfif>
<cfreturn trim(theRegion) />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment