Link to home
Start Free TrialLog in
Avatar of TobinLewis
TobinLewis

asked on

Deleting Session Variables with Checkbox - 500 points

We are currently using client variables to set the search criteria for our search pages and we would like to move them over to session variables due to the database load they are putting on our SQL server.  I have been successful moving over some of the variables to session variables, but I am getting stuck on session variables that are being set through the use of a check box on a form.  

Once I check the checkbox, the session variable intdata is set, but when I try to uncheck the intdata checkbox, the box stays checked.  This is the same code that is used for the client variables and they check and uncheck correctly.  What am I missing????

Below is some of the code that sets the variable and the code of the form with the checkboxes.  I have been trying to use the StructDelete for the intdata variable, but it doesn't seem to be deleting the session variable.  

Setting and Deleting the Variable

<!--- Int Data --->
<CFIF isdefined("form.intdata")>
<cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
      <CFSET session.intdata = 1>
</cflock>
</cfif>

<CFIF isdefined("url.keepInt") and isdefined("session.intdata")>
      <CFELSEIF not isdefined("form.intdata") and isdefined("session.intdata")>
            <cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
                  <CFSET StructDelete (session, "intdata")>
            </cflock>
</cfif>


Code of the form with checkbox.

<form action="InterestForm.cfm" method="post" name="Form">
<table width="100" border=1 bordercolor="000000" cellpadding=0 cellspacing=0 bgcolor="AFCEE2">
      <tr>
            <td>
                  <table>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntData" value="0" onClick="int_onchange()" <CFIF isdefined("session.intdata")> Checked</cfif>>
                  </td>
                  <td align="center" >Data
                  </td>
                  </tr>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntPeople" value="0" onClick="int_onchange()" <CFIF isdefined("client.intpeople")> Checked</cfif>>
                  </td>
                  <td align="center">People
                  </td>
                  </tr>
                  <tr>
                  <td>
                  <input type ="checkbox" name="IntThings" value="0" onClick="int_onchange()" <CFIF isdefined("client.intthings")> Checked</cfif>>
                  </td>
                  <td align="center">Things
                  </td>
                  </tr>
                  </table>
            </td>
      </tr>
</table>
</form>

If there is more information that you need, please let me know.

Thanks,

Tobin      
Avatar of pinaldave
pinaldave
Flag of India image

Hi TobinLewis,
 
how about trying this StructClear(session.intdata);

Regards,
---Pinal
Avatar of TobinLewis
TobinLewis

ASKER

Hi,

When I tried StructClear(session.intdata) I received the following error.

An error occurred while evaluating the expression:

StructClear(session.intdata)

Error near line 26, column 9.
--------------------------------------------------------------------------------

Cannot convert given value to a struct. Please check the validity of the expression

StructClear(session) if you do this compolite structure will be cleared.
Hi,

I ended up trying the same code that I started with and it seems to be working now.

<CFIF isdefined("url.keepInt") and isdefined("session.intdata")>
      <CFELSEIF not isdefined("form.intdata") and isdefined("session.intdata")>
      <cflock timeout="30" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
            <CFSET StructDelete(session,"intdata")>
      </cflock>
</cfif>

Thanks for your help.

Tobin
Do not use StructClear(session.intdata), its actually structClear( session )
because it clears the whole session scope including CFTOKEN etc.. use structDelete as you have it..

Best thing to do is set everything in another structure, example;

<cfset session.savedData = structNew() />
<cfset session.savedData.something1 = "some data 1" />
<cfset session.savedData.something2 = "some data 2" />
<cfset session.savedData.something3 = "some data 3" />

You can call it like #session.savedData.something3# and you can delete everything with one line of code
<cfset structDelete( session, "savedData" ) />

Having said all that, saving search criteria in the session scope is not a good idea at all, its best to pass this on via the form scope.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial