A good example of the usage of cfparam involves when you're using <input type=checkbox> on a form.
If the user doesn't check the checkbox, the form field is not posted at all, so an attempt to evaluate it using form.checkboxfield (example) results in "field undefined in form" error. Using <cfparam name="form.checkboxfield" default=0> on your form processing page alleviates that problem nicely. If the checkbox is checked (assuming the checked value is 1), form.checkboxfield evaluates to 1. If it's not checked, it evaluates to 0 because of the <cfparam> tag. Of course there are a million other uses for it, but I think the first time I ever used it was in that context. -- Josh ----- Original Message ----- From: "Ben Nadel" <[EMAIL PROTECTED]> To: "CF-Talk" <[email protected]> Sent: Thursday, June 01, 2006 2:01 PM Subject: RE: if/switch cf:set/param > Paul, > > CFSwitch I believe is faster (slightly) , and I think easier to read. > Also, > the default case does not need to be the last case (as opposed to an ELSE > statement). However, the tradeoff is that the case values have to be > contstants. > > For IF statements, the benefits are the possibility of dynamic comparisons > (ie. URL.x EQ URL.y ). > > Mostly though, it's a matter of personal preference I think. > > Cfset sets a value into a variable. Cfparam checks to see if a variable > already exists. If it does not exist and a default was provided, it sets > that value into the variable. If no default exists, it throws an error. I > think there are a lot of different opinions on why/when it is appropriate > to > use CFParam vs setting a variable. > > I like to CFParam all my FORM variables and custom tag ATTRIBUTES (as an > example). I like to know that a value exists, even if it isn't correct, > because then I can validate afterwards. However, in Custom tags, I > ususally > don't have default values for all my attribute params so that CF will > throw > an error if the user does not provide the attribute. > > If by variable pools, you mean scopes (ex. APPLICATION, SESSION, REQUEST), > they are fantastic! I scope (define within the context of a "variable > poo", > ex. FORM.first_name) anything that is either submitted to a page or is > available in more than one template. > > So for example, if I use an index variable that is for only one template, > I > might use intChild, but if I use a variable that is set in one template > and > used in another, I might use something like REQUEST.ChildIndex... It > becomes > a naming convention that I love because the structure of the variable > helps > explain what it is and where it was set/available. > > There is lots to know about the different scopes and how widely accessible > they are. Check out the main ones in the live docs. > > ....................... > Ben Nadel > www.bennadel.com > > -----Original Message----- > From: Paul Ihrig [mailto:[EMAIL PROTECTED] > Sent: Thursday, June 01, 2006 3:55 PM > To: CF-Talk > Subject: cf:if/switch cf:set/param > > ok. > just looking at a bunch of code. > > most pages use a combo of if & switch > what are the reasons to use one over the other. > > also what is the difference between cfset & cfparam. > i know cfset sets the variable you want to be but dosnt cfparam also do > this? > > also what should i know about variable pools? > > thanks > -paul > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:241983 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

