Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store Client or Session variable?

Status
Not open for further replies.

evergrean100

Technical User
Dec 1, 2006
115
US
I have a form that covers 5 pages and I pass the form variables from one page to another until it gets to page 5 where all form variables are submitted to action page.
If someone quits or stops during one of the pages is there anyway to store their inputs so when they come back about 1 to 10 hours later it will show their past inputs and they can continue on?

Iam not sure if I use a client session or what and how does that work??
Code:
<cfset session.SessionCity = #city#>

<form...
<cfif isDefined("session.SessionCity")>
<input type="text" name="city" value="#session.SessionCity#">
<cfelse>
<input type="text" name="city">
</cfif>

<input type="submit" value="Continue to next page">
</form>

Please advise.

 
Hi evergrean,

the best way to store these are to lob them into session variables... if you know all the relevant fields you are best to pre-create all of these using <cfparam ...> for your city example I would use the following:

Code:
    <!--- define defaults --->
    <cfparam name="session.FormName.city" default="" />

this means that even before the user arives at your form you are sure that all fields have already been created. This in turn means that you don't have to check the session for them and can always use them. The reason I would use <cfparam ...> in stead of <cfset ...> is that it will only create the variable if it does not already exists, this will ensure that you don't have to create a bunch of if statements like these:

Code:
    <!--- define defaults --->
    <cfif Not IsDefined("session.FormName.city")>
      <cfset session.FormName.city = "" />
    </cfif>

    <!--- show input for city --->
    <cfif Not IsDefined("session.FormName.city")>
      <input type="text" name="city" id="city" value="" />
    <cfelse>
      <input type="text" name="city" id="city" value="#session.FormName.city#" />
    </cfif>

However if you wish to store these values for a longer period of time then you are best of storing them within a cookie using <cfcookie ...>

Also the last bit of advise I can give you is to ensure you create your form it's own structure within the session or cookie just so it is easier to clean up afterwards, as you can wipe the entire structure clean on a final submit of the form otherwise you will have to reset or wipe each individual variable. e.g.:

Code:
    <!--- form has been submitted, now clear session vars --->
    <cfset session.country = "" />
    <cfset session.state = "" />
    <cfset session.city = "" />

VS.

Code:
    <!--- form has been submitted, now clear session vars --->
    <cfset session.FormName = StructNew() />

hope this helps you along the way, if it doesn't then let me know.

B.

We never fail, we just find that the path to succes is never quite what we thought...
 
Thanks,

Please advise if this is correct?
Code:
<cfparam name="session.myFormName.city" default="" />

<form name="myFormName"  ...>
<input type="text" name="session.FormName.city"  value="" />

...
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top