CFML: not sure how this CFIF statement is passing as true

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
<CFIF StructKeyExists(FORM, "photo_file_1")
AND (StructKeyExists(FORM, "photo_file_1") NEQ "")
AND (StructKeyExists(FORM, "photo_1_select_for_action") EQ "YES")>

<!--- above asks if the form value exists, it has a value, and the relative "select for action" variable has been tagged as yes --->

<CFFILE

action="upload"
destination="c:\images\"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_1"
>

</CFIF>

However, I'm submitting the form with form.photo_1_select_for_action equal to NO and have verified it in my debugging info.

Yet it is still attempting the CFFILE operation. So it is passing the function as true when it is not. What am I doing wrong here??

not sure what I am doing wrong here.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
<CFIF StructKeyExists(FORM, "photo_file_1")
AND (StructKeyExists(FORM, "photo_file_1") NEQ "")
AND (StructKeyExists(FORM, "photo_1_select_for_action") EQ "YES")>

<!--- above asks if the form value exists, it has a value, and the relative "select for action" variable has been tagged as yes --->

<CFFILE

action="upload"
destination="c:\images\"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_1"
>

</CFIF>

However, I'm submitting the form with form.photo_1_select_for_action equal to NO and have verified it in my debugging info.

Yet it is still attempting the CFFILE operation. So it is passing the function as true when it is not. What am I doing wrong here??

not sure what I am doing wrong here.

Give this a shot

<CFIF ((StructKeyExists(FORM, "photo_file_1"))
AND (StructKeyExists(FORM, "photo_file_1") NEQ "")
AND (StructKeyExists(FORM, "photo_1_select_for_action") EQ "YES"))>
 

darktubbly

Senior member
Aug 19, 2002
595
0
0
StructKeyExists returns true or false, which means your code is only checking to see whether these fields have a value. Correct code should be:

Code:
<cfif StructKeyExists(FORM, "photo_file_1") 
AND StructKeyExists(FORM, "photo_1_select_for_action") 
AND FORM.photo_file_1 NEQ "" 
AND FORM.photo_1_select_for_action EQ "YES">
...
</cfif>