[thelist] cf redirection

jeff jeff at members.evolt.org
Mon Jul 17 13:57:22 CDT 2000


palyne,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: "Palyne Gaenir" <palyne at sciencehorizon.com>
:
: <cflocation url="page.cfm?formtype=menu&note=upd">
:
: And then on the switch section for the menu page I just insert
: something like
:
: <cfoutput>
: <cfif IsDefined(NOTE)>
: <cfif #NOTE# IS 'upd'>
: <p>Your record has been updated.</p>
: <cfelseif #NOTE# IS 'add'>
: <p>Your record has been added.</p>
: <cfelseif #NOTE# IS 'del'>
: <p>That record is gone, gone, gone.</p>
: </cfif>
: </cfif>
: </cfoutput>
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

this is another approach, however, let me show you a couple of ways to make
it better, then a couple of it's shortcomings.

first, the IsDefined() function isn't the fastest way to check for the
existence of a value.  if you're already putting some conditional logic in
place for a variable, then cfparam it somewhere.  instead of checking if
it's defined, just check it's length.

<cfparam name="note" default="">

<cfif Len(note)>
  <cfif note IS 'upd'>
    <p>Your record has been updated.</p>
  <cfelseif note IS 'add'>
    <p>Your record has been added.</p>
  <cfelseif note IS 'del'>
    <p>That record is gone, gone, gone.</p>
  </cfif>
</cfif>

since you're using multiple if/elseif statements, then it would be even
better to throw it into a cfswitch without a cfdefaultcase

<cfswitch expression="#note#">
  <cfcase value="upd">
    <p>Your record has been updated.</p>
  </cfcase>
  <cfcase value="add">
    <p>Your record has been added.</p>
  </cfcase>
  <cfcase value="del">
    <p>That record is gone, gone, gone.</p>
  </cfcase>
</cfswitch>

all this work brings up another point, however.  what do you do in the
situation where you need to pass a different message to the page?  or, does
it make much sense to place this much conditional logic just to display a
message when you can control when/where/what message gets set to begin with?
i guess that's why i've gone to the method that isaac described.  it's more
flexible, requires less code, and in turn less processing time, and is
really easy to move from page to page without editing.

just my 2¢,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org
jeff at members.evolt.org






More information about the thelist mailing list