Whatever message this page gives is out now! Go check it out!

IsDefined

Last update:
May 18, 2026

Description

Evaluates a string value to determine whether the variable named in it exists. This function is an alternative to the ParameterExists function, which is deprecated.

Returns

True, if the variable is found; False, otherwise.

Category

Syntax

IsDefined(variable)

See also

History

ColdFusion (2018 release): Introduced named parameters.
ColdFusion MX: Changed behavior: this function can process only the following constructs:
  • A simple variable
  • A named variable with dot notation
  • A named structure with dot notation (for example: mystruct.key)

Parameters

Parameter
Description
variable
String, enclosed in quotation marks. Name of variable to test for.

Usage

Passing an array entry, such as myArray[3] to this function causes an error. To check whether a specific entry exists in an array, use the ArrayIsDefined function.You can test whether a specific key exists in a structure by using this function or the StructKeyExists function. For example, when working with scopes that ColdFusion exposes as structures, the StructKeyExists function can sometimes replace this function. The following lines are equivalent:
if(isDefined("form.myVariable")) 
if(structKeyExists(form,"myVariable"))

Example

 
<cfscript>
    myarray=["1","4","23","5","54"];
    for(i=1; i <= arrayLen(myarray); i++){
    writeoutput(myarray[i] & "<br>");
    }
    writeOutput(isDefined("myarray"))
</cfscript>
Output
1

4

23

5

54

YES

Real-world uses of the isDefined function

Form validation and processing

A customer relationship management (CRM) system processes contact forms from multiple sources, including website contact forms, newsletter signups, and lead generation campaigns. Each form may have different required and optional fields, creating challenges for consistent data processing. How it helps:
  • A single processing system handles all form variations
  • Safe field checking eliminates crashes from missing data
  • Business logic adjusts based on available form fields
  • Forms work reliably regardless of completion level
<cfscript>
    // Simple Form Processing with IsDefined
    // Business: Contact form with optional fields
    
    // Sample form submissions
    forms = [
        {
            name: "John Smith",
            email: "john@company.com",
            message: "Interested in your services",
            phone: "555-123-4567",
            company: "Tech Corp"
        },
        {
            name: "Sarah Wilson", 
            email: "sarah@startup.com",
            message: "Quick question about pricing"
            // Missing phone and company
        }
    ];
    
    // Simple form processing function
    function processForm(formData) {
        var result = "Form Processing Result:<br><br>";
        
        // Check required fields
        if (isDefined("formData.name") AND isDefined("formData.email") AND isDefined("formData.message")) {
            result &= "✅ <strong>SUCCESS!</strong><br>";
            result &= "<strong>Name:</strong> " & formData.name & "<br>";
            result &= "<strong>Email:</strong> " & formData.email & "<br>";
            result &= "<strong>Message:</strong> " & formData.message & "<br>";
            
            // Check optional fields safely
            if (isDefined("formData.phone")) {
                result &= "<strong>Phone:</strong> " & formData.phone & "<br>";
            } else {
                result &= "<strong>Phone:</strong> Not provided<br>";
            }
            
            if (isDefined("formData.company")) {
                result &= "<strong>Company:</strong> " & formData.company & "<br>";
            } else {
                result &= "<strong>Company:</strong> Not specified<br>";
            }
            
        } else {
            result &= "❌ <strong>FAILED - Missing required fields</strong><br>";
        }
        
        return result;
    }
</cfscript>

<cfoutput>
    <h1>📝 IsDefined: Form Processing Demo</h1>
    <p><strong>Business Need:</strong> Handle contact forms with optional fields</p>
    <p><strong>Challenge:</strong> Some form fields might be missing</p>
    <p><strong>Solution:</strong> Use isDefined() to check before accessing</p>
    <hr>
    
    <h2>Example 1: Complete Form</h2>
    <div style="background: ##d4edda; padding: 15px; border-radius: 5px;">
        #processForm(forms[1])#
    </div>
    
    <h2>Example 2: Partial Form (Missing Optional Fields)</h2>
    <div style="background: ##d4edda; padding: 15px; border-radius: 5px;">
        #processForm(forms[2])#
    </div>
    
</cfoutput>

URL parameter handling for eCommerce product filtering

An eCommerce platform with 50,000+ products provides advanced search and filtering capabilities through URL parameters. Customers access product listings through various routes including search engines, category browsing, and direct links, each potentially passing different parameter combinations. How it helps:
  • Robust parameter processing for all entry points
  • Clean URLs work with any parameter combination
  • Safe parameter access eliminates crashes from missing values
  • Advanced search features work reliably with optional parameters
<cfscript>
    // Simple URL Parameter Handling with IsDefined
    // Business: Product search with optional filters
    
    // Sample URL parameters (normally from URL scope)
    urlParams = [
        {
            keyword: "laptop"
            // Basic search - no filters
        },
        {
            keyword: "laptop",
            brand: "dell", 
            price: "500-1000",
            rating: "4"
            // Advanced search with filters
        }
    ];
    
    // Simple search function
    function buildSearch(params) {
        var result = "Search Results:<br><br>";
        
        // Check for required keyword
        if (isDefined("params.keyword")) {
            result &= "🔍 <strong>Searching for:</strong> " & params.keyword & "<br>";
            
            var filters = [];
            
            // Check optional filters safely
            if (isDefined("params.brand")) {
                arrayAppend(filters, "Brand: " & params.brand);
            }
            
            if (isDefined("params.price")) {
                arrayAppend(filters, "Price: $" & params.price);
            }
            
            if (isDefined("params.rating")) {
                arrayAppend(filters, "Rating: " & params.rating & "+ stars");
            }
            
            if (arrayLen(filters) > 0) {
                result &= "<strong>Filters:</strong> " & arrayToList(filters, ", ") & "<br>";
            } else {
                result &= "<strong>Filters:</strong> None applied<br>";
            }
            
            result &= "<strong>Status:</strong> ✅ Search ready<br>";
            
        } else {
            result &= "❌ <strong>No search keyword provided</strong><br>";
        }
        
        return result;
    }
</cfscript>

<cfoutput>
    <h1>🔗 IsDefined: URL Parameter Demo</h1>
    <p><strong>Business Need:</strong> Handle product search with optional filters</p>
    <p><strong>Challenge:</strong> URL parameters vary by user and page</p>
    <p><strong>Solution:</strong> Use isDefined() to check what's available</p>
    <hr>
    
    <h2>Example 1: Basic Search (keyword only)</h2>
    <div style="background: ##e3f2fd; padding: 15px; border-radius: 5px;">
        #buildSearch(urlParams[1])#
    </div>
    
    <h2>Example 2: Advanced Search (with filters)</h2>
    <div style="background: ##e3f2fd; padding: 15px; border-radius: 5px;">
        #buildSearch(urlParams[2])#
    </div>
    
</cfoutput>

Configuration management in a multi-tenanted SaaS platform

A Software-as-a-Service platform serving 1,000+ clients provides customizable features and configurations. Each client has different feature requirements, pricing tiers, and custom settings, requiring flexible configuration handling without hardcoded assumptions about setting availability. How it helps:
  • Safe handling of optional settings across all client tiers
  • Easy activation of new features without deployment risks
  • Smooth experience regardless of configuration completeness
  • Faster feature rollouts with confident configuration handling
<cfscript>
    // Simple Configuration Management with IsDefined
    // Business: Handle optional application settings
    
    // Sample configurations
    configs = [
        {
            appName: "My ColdFusion App",
            version: "1.0.0"
            // Basic config - missing optional settings
        },
        {
            appName: "My ColdFusion App", 
            version: "1.0.0",
            debugMode: true,
            emailEnabled: true,
            cacheEnabled: true,
            logLevel: "INFO"
            // Full config with all optional settings
        }
    ];
    
    // Simple configuration loader
    function loadConfig(configData) {
        var result = "Configuration Loaded:<br><br>";
        
        // Load basic required settings
        if (isDefined("configData.appName")) {
            result &= "<strong>App Name:</strong> " & configData.appName & "<br>";
        } else {
            result &= "<strong>App Name:</strong> Default App<br>";
        }
        
        if (isDefined("configData.version")) {
            result &= "<strong>Version:</strong> " & configData.version & "<br>";
        } else {
            result &= "<strong>Version:</strong> 1.0.0<br>";
        }
        
        // Check optional features safely
        if (isDefined("configData.debugMode")) {
            result &= "<strong>Debug Mode:</strong> " & (configData.debugMode ? "Enabled" : "Disabled") & "<br>";
        } else {
            result &= "<strong>Debug Mode:</strong> Disabled (default)<br>";
        }
        
        if (isDefined("configData.emailEnabled")) {
            result &= "<strong>Email Service:</strong> " & (configData.emailEnabled ? "Enabled" : "Disabled") & "<br>";
        } else {
            result &= "<strong>Email Service:</strong> Disabled (default)<br>";
        }
        
        if (isDefined("configData.cacheEnabled")) {
            result &= "<strong>Cache:</strong> " & (configData.cacheEnabled ? "Enabled" : "Disabled") & "<br>";
        } else {
            result &= "<strong>Cache:</strong> Disabled (default)<br>";
        }
        
        if (isDefined("configData.logLevel")) {
            result &= "<strong>Log Level:</strong> " & configData.logLevel & "<br>";
        } else {
            result &= "<strong>Log Level:</strong> ERROR (default)<br>";
        }
        
        result &= "<br>✅ <strong>App started successfully!</strong>";
        
        return result;
    }
</cfscript>

<cfoutput>
    <h1>⚙️ IsDefined: Configuration Demo</h1>
    <p><strong>Business Need:</strong> Handle optional application settings</p>
    <p><strong>Challenge:</strong> Different environments have different config completeness</p>
    <p><strong>Solution:</strong> Use isDefined() with sensible defaults</p>
    <hr>
    
    <h2>Example 1: Basic Configuration</h2>
    <div style="background: ##fff3cd; padding: 15px; border-radius: 5px;">
        #loadConfig(configs[1])#
    </div>
    
    <h2>Example 2: Full Configuration</h2>
    <div style="background: ##d1ecf1; padding: 15px; border-radius: 5px;">
        #loadConfig(configs[2])#
    </div>
    
</cfoutput>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page