Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created October 13, 2011 13:25
Show Gist options
  • Save orangexception/1284209 to your computer and use it in GitHub Desktop.
Save orangexception/1284209 to your computer and use it in GitHub Desktop.
storeStructIntoSession
<cffunction name= "storeStructIntoSession"
output= "false"
hint= "I store a form into the session scope">
<cfargument name= "stTarget"
required= "true"
hint= "I am the target struct for storage." />
<cfargument name= "sSessionKey"
required= "false"
default= "#createUUID()#"
hint= "I am the session key for the struct." />
<cfargument name= "bIgnoreEmptyFields"
required= "false"
default= "false"
hint= "I am a toggle that will ignore empty keys." />
<cfargument name= "lsKeysToIgnore"
required= "false"
default= ""
hint= "I am a list of struct keys to ignore." />
<cfset var stCopy= duplicate( stTarget ) />
<cfset var sKey= "" />
<cfloop collection= "#stCopy#"
item= "sKey">
<cfif listFindNoCase( lsKeysToIgnore , sKey )
or ( bIgnoreEmptyFields and len( stCopy[ sKey ] ) eq 0 )>
<cfset StructDelete( stCopy , sKey ) />
</cfif>
</cfloop>
<cflock scope= "session"
type= "exclusive"
timeout= "15">
<cfset session[ sSessionKey ]= stCopy />
</cflock>
<cfreturn sSessionKey />
</cffunction>
<!--- Store Form scope into session.plansearch --->
<cfif structKeyExists( form , "fieldnames" )>
<cfset storeStructIntoSession( stTarget= form ,
sSessionKey= "plansearch" ,
bIgnoreEmptyFields= true ,
lsKeysToIgnore= "fieldnames,submit" ) />
</cfif>
@jeffcoughlin
Copy link

jeffcoughlin commented Nov 14, 2011 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment