Requiring Users To Enter Values In Form Fields - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

Ensuring that Variables Exist
For example, the following series of
form variables named StartRow and RowsToFetch:
<cfparam name="Form.StartRow">
<cfparam name="Form.RowsToFetch">
If the page with these tags is called without either one of the form variables, an error
occurs and the page stops processing. By default, ColdFusion displays an error
message; you can also handle the error as described in Chapter 11, "Preventing and
Handling Errors" on page 191.
Example: setting default values
This example uses
processing continues. If they do not exist, they are created and set to the
value.
<cfparam name="Cookie.SearchString" default="temple">
<cfparam name="Client.Color" default="Grey">
<cfparam name="ShowExtraInfo" default="No">
You can use
using conditional logic. For example, the action page could have the following code
to ensure that a
<cfparam name="Form.SelectedDepts" default="Marketing,Sales">

Requiring users to enter values in form fields

One of the limitations of HTML forms is the inability to define input fields as
required. Because this is a particularly important requirement for database
applications, ColdFusion provides a server-side mechanism for requiring users to
enter data in fields.
To require entry in an input field, use a hidden field that has a
composed of the field name and the suffix "_required." For example, to require that
the user enter a value in the FirstName field, use the syntax:
<input type="hidden" name="FirstName_required">
If the user leaves the FirstName field empty, ColdFusion rejects the form submittal
and returns a message informing the user that the field is required. You can
customize the contents of this error message using the
field. For example, if you want the error message to read "You must enter your first
name," use the following syntax:
<input type="hidden"
cfparam
to set default values for URL and Form variables, instead of
cfparam
SelectDepts
name="FirstName_required"
value="You must enter your first name.">
tags indicates that this page expects two
cfparam
to see if optional variables exist. If they do exist,
variable exists:
default
attribute
name
attribute of the hidden
value
89

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents