Search code examples
coldfusioncoldfusion-9cfqueryparam

Struckt Key Exists in cfqueryparam?


I have form fields with checkbox fields. On my cfc page I would like to use strucktKeyExists to check if checkbox form fields exist when I run my Insert/Update query. Also I have null attribute in my cfqueryparam that will set value to true/false if value/field doesn't exist. Here is example of my code:

dm_ck0 = <cfqueryparam value="#trim(structKeyExists(FORM, 'frm_ck0'))#" cfsqltype="cf_sql_bit" maxlength="1" null="#yesNoFormat(!len(trim(structKeyExists(FORM, 'frm_ck0'))))#" /> 

So when I submit my form checkbox field is unchecked. I got an error message back:

Invalid data value NO exceeds maxlength setting 1.

I'm not sure why this message showed up. Before I set StrucktKeyExist() in my cfqueryparam my code worked fine. If anyone see where my code is failing please let me know. Thanks!


Solution

  • First, set the variable:

    myVar = structKeyExists(FORM, 'frm_ck0') ? 1 : 0;
    

    Use your variable in the query parameter

    dm_ck0 = <cfqueryparam value="#myVar#" cfsqltype="cf_sql_bit">