![]() |
| Products | Services | Clients | Contact | Company | Home |
|
DemoIn this demo you will see how CF_Param assigns a default value to a variable when an incorrect type is specified. First, lets take a look at <cfparam> and its drawbacks. In this example, we have a URL variable called PageID that needs to be of type numeric. <cfparam name="url.PageID" default="0"> <cfquery name="getPage"> SELECT * FROM Pages WHERE PageID = #url.PageID# </cfquery> As you can see, if url.PageID is not a number, an error will be thrown in the query. This is not ideal as valuable database information could be given away. This is where CF_Param comes in. <CF_Param VarName="url.PageID" Default="0"> <cfquery name="getPage"> SELECT * FROM Pages WHERE PageID = #url.PageID# </cfquery> Here, if url.PageID is not a number, it will get the default of 0. Perfect! Want to see an example? PageID = 0Click here to reload this page with a PageID of 10. The value above should be 10. Click here to reload this page with a PageID of test. The value above should be 0, since that is the default value when a non-numeric value is passed. Related Links |