CFPARAM and How to Uncheck a CheckboxFor anyone new to application development, you may be perplexed when you create your form for editing some data that should allow a user to uncheck a checkbox and update a record to a status of not checked. You will sooner or later discover an oddity about HTML forms. HTML forms won't allow you to uncheck like you think you should be able to. If you uncheck the checkbox, the value becomes NULL and the form doesn't bother to pass the field. You will find that ColdFusion does have a simple solution and much more with the CFPARAM tag. CFPARAM primary function is to provide a default value if one isn't provided from a requesting form, a URL, or from some other expected variable like a session ID. It also provides a nice way to check the passed values datatype which comes in handy when you need to assure that a numeric value, date or other datatype is passed. Setting Defaults without
CFPARAM
This sets a MyVar to have a NULL value. It now exists and has a NULL value. Checking Datatypes
without CFPARAM Setting Defaults with
CFPARAM
If MyVar is not passed to the page it will be created with this tag. In this case it will exist with a NULL value. Checking Datatypes
with CFPARAM Datatypes that can be checked with CFPARAM
Summary CFPARAM is a great tool in setting defaults and dealing with form fields that are passed with no value. It also helps in maintaining your data integrity by checking datatypes
More CFNewbie?com Articles |