Saving Form Variables as Session Variables the Wrong Way

A student approached me the other day. She were gathering search criteria in a form and wanted to save the criteria to a session variable. But when she moved from page to page, her session variable lost its values.

<cfif isdefined('form.submit')>
<cfset session.saveformvars = structnew()>
<cfset session.saveformvars = form>
</cfif>

The issue is with the the variable scoping that takes place on a form structure. Forms have a local "non-persistent" variable scope (they are only specific to that page, or the page called from the form and don't hang around).

Session variables are by nature persistent, or can exist beyond a single page, lasting for the user's session length.

When the entire form structure was saved as a session variable structure as above, that session structure received the same scoping as the form structure.

So...

<cfset session.saveformvars = form>
<!--- makes session.saveformvars now a local scoped variable and not a session scoped variable --->

Since this student wanted to only save those form fields that were had been completed and do some data tweaking on the information, I had her rewrite the snipped of code to loop through the form, pick out the variables to keep, then save those to the session variable.

<cfset session.plansearch = structnew()>
<cfloop collection="#form#" item='key'>
<!--- pick out null fields, and son't save the submit button or the "FieldNames" key from the form struct --->
<cfif form[key] neq '' and form[key] gt 0 and key neq 'fieldnames' and key neq 'submit'>
<cfset "session.plansearch.#key#" = form[key]>
</cfif>
</cfloop>

Now this student had her trimmed form list saved as a structure in the format she wanted.

Quick & Dirty -- Opening Editable Illustrator Vector Images in Fireworks

I have created a Vector image in Illustrator that I want to open in FW CS3. FW CS3 doesn't integrate well with AI files, and EPS files usually import as bitmap.

To open a vector Illustrator file in Fireworks CS3, to this:

1) In Illustrator, save as .eps, then choose a legacy Illustrator 8 version.

2) In Fireworks, import that newly saved .eps file and you should import all the paths and and shape along with it.

There may be some fine tuning involved, but at least you are not recreating the image

Quick & Dirty: Using LightBox with Image maps

Lightbox technique is very cool way to view enlarged photos, details for text etc. I use Four Level's extension but didn't know if it would work in an image map situation.

It does. I set the lightbox up to link to a normal image, allowing the jquery and other scripts to be copied over to the website directory. Then I updated the image map to contain the reference code to the popup instead of the image.

In the example below, each area mapping has only a 'rel' added, and a ref for the photo to be shown. Quite simple.



<img src="../images/dbfloorplan.jpg" name="floorplan" width="600" height="370" border="0" usemap="#floorplanMap" relalt="" />

<map name="floorplanMap" id="floorplanMap">
<area shape="rect" coords="234,14,314,81" rel="lightbox[tour]" ref="../images/office/bob.jpg" title="Estimator's Office" />
<area shape="rect" coords="357,13,518,81" rel="lightbox[tour]" href="../images/office/elizabeth.jpg" title="Elizabeth's Office" />
<area shape="rect" coords="523,13,591,147"rel="lightbox[tour]" href="../images/office/deck.jpg" title="Trex Decking" />
:
<!--- and so forth --->
:
</map>

Quick & Dirty Right SideBar ... or Not,

If you have a site that you some pages to have a sidebar and some NOT without having to create 2 similar templates (if you are using DW Template feature), you can easily set a variable in the file to turn the side bar on or off. This method creates a floating right sidebar if the variable is set, but it can be adjusted for a left sidebar as well.

There are two quick and dirty methods of doing this. The first involves a dynamic div creation by setting up the Div id to be evaluated at run time using 2 CSS ids, one for content width accommodating the sidebar and one without:


<div id="<cfoutput>#IIF(useRtSideBar eq true, DE('contentwsidebar'), DE('content'))#</cfoutput>">
Put Content Stuff Here

<div id='sidebar' style="<cfoutput>#IIF(useRtSideBar eq true, DE('display:block'), DE('display:none'))#</cfoutput>">
Put Your SideBar Stuff Here
</div>
</div>

The second is a more basic method that simply shows or hides the sidebar div based on the setting of the variable:


<head>
<cfset useRtSideBar = true>
:
</head>
<body>
<div id='banner'> banner here </div>
<div id='nav'> nav here </div>
<div id='contentwrapper'> Wraps Content and Sidebar
<cfif useRdSideBar>
<div id='rtsidebar> Sidebar </div>
</cfif>

Rest of Content goes here
</div> <!---contentwrapper --->
</body>

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact HHWD