I have a set of radio buttons that I would like to validate on the server side. First I created structure that has the argument names for the key. Then each name is set to different values that the radio button can have. Here is an example:
<cfargument name="frmhs_rad1" type="string" required="false" default="">
<cfargument name="frmhs_rad2" type="string" required="false" default="">
<cfargument name="frmhs_rad3" type="string" required="false" default="">
<cfset validateRadio = {
frmhs_rad1 = 0,
frmhs_rad1 = 1,
frmhs_rad2 = 0,
frmhs_rad2 = 1,
frmhs_rad2 = 2,
frmhs_rad3 = 0,
frmhs_rad3 = 1,
frmhs_rad3 = 2
}>
Here is an example of one of my cfqueryparam
lines:
<cfqueryparam value="#trim(structKeyExists(validateRadio, arguments.frmhs_rad1) ? validateRadio[arguments.frmhs_rad1]:"")#" cfsqltype="cf_sql_char" null="#yesNoFormat(!len(trim(arguments.frmhs_rad1)))#" />
If I don't check the radio button the value in my Database will remain NULL
. If I check the radio button then I see a blank space in this field. I think that my code should prevent that. If value exists then I check if it's valid in validateRadio
structure. If value doesn't exist then it should be set to NULL
. I'm not sure why my code is failing. Can anyone see the problem with my code?