我是ColdFusion的新手。我正在嘗試做一些表單字段驗證。但是,如果form.name
和form.address
字段爲空,我的CFIF似乎不工作。ColdFusion CFIF
這裏是我的代碼:
<cfif IsDefined("form.name")>
<cfif IsDefined("form.address")>
Your shipping address is:<br>
<cfoutput>
#form.name#<br>
#form.address#<br>
#form.state#<br>
#form.shipping#<br>
#form.brochure#<br>
</cfoutput>
<cfelse>
You did not enter an address.
</cfif>
<cfelse>
You did not enter a name.
</cfif>
由於Carl寫了使用** StructKeyExists **而不是IsDefined,只要你100%確定你在結構中尋找變量(幸運的是變量範圍是結構)。第一個函數僅在所提到的範圍內查找特定的鍵,而IsDefined將在所有範圍內查找它。 – PatNowak 2015-07-21 17:57:17