Cornfeed.com - Growing tomorrow's e-business
My Account

Sign-in to access your account.
Information

Version: 0.3
Release Date: 4/22/03
Size: 1kb



Navigate
  • Usage and Documentation
  • Online Demo
  • Download




  • « Return to Overview

    Demo

    In 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 = 0

    Click 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

    Usage and Documentation
    Online Demo
    Download

    Copyright © Cornfeed.com 1999-2008