> Please check out the below code, I would like to show users a 
> previous search history and everything seems to work ok 
> except that on the first time through it appends the seach 
> phrase twice. I understand why it is happening, (due to the 
> 2nd conditional statement) but cannot figure out a better 
> way. Maybe someone can test it out for me, and give me a 
> pointer. Thanks a bunch!!!
> 
> cookieTest.cfm
> 
> <!---IF OUR COOKIE IS NOT SET, SET IT NOW ---> <cfif not 
> isDefined('cookie.testCookie') AND isDefined('form.test')> 
> <CFCOOKIE name="testCookie" value="#form.test#" 
> expires="never"> </cfif> <!---IF OUR COOKIE IS SET AND THE 
> LEN IS LT 5, ADD TO IT---> <cfif 
> isDefined('cookie.testCookie') AND listLen(cookie.testCookie, 
> ",") LT 6 AND isDefined('form.test')> <cfset searchList = 
> listAppend(cookie.testCookie, form.test, ",")> <CFCOOKIE 
> name="testCookie" value="#searchList#" expires="never"> 
> </cfif> <!---IF OUR COOKIE IS LEN IS EQ 5 THEN DELETE THE 
> FIRST ELEMENT AND APPEND THE LIST---> <cfif 
> isDefined('cookie.testCookie') AND listLen(cookie.testCookie, 
> ",") GTE 6 AND isDefined('form.test')> <cfset deleted = 
> listDeleteAt(cookie.testCookie, "1")> <CFCOOKIE 
> name="testCookie" value="#deleted#" expires="never"> </cfif>

I didn't actually try running the code, but it looks like the first two of
those CFIF comparisons will evaluate to true, because you're changing the
evaluation conditions for the next CFIF within the previous one. When the
first CFIF sets the cookie, the second CFIF's evaluation condition will
become true. Instead of having three separate CFIFs, why not use CFELSE
and/or CFELSEIF for some of these?

<cfif IsDefined("Form.test")>
        <cfif not IsDefined("Cookie.testCookie")>
                <cfset searchList = Form.test>
        <cfelse>
                <cfif ListLen(Cookie.testCookie) lt 6>
                        <cfset searchList = ListAppend(Cookie.testCookie,
Form.test)>
                <cfelse>
                        <cfset searchList = ListDeleteAt(Cookie.testCookie,
1)>
                </cfif>
        </cfif>
        <cfcookie name="testCookie" value="#searchList#" expires="never">
</cfif>

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7 
Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs 
http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:267226
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to