我是ColdFusion的新手.我正在尝试进行一些表单字段验证.但是,如果form.name和form.address字段为空,我的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>
Run Code Online (Sandbox Code Playgroud) 这可能是一个愚蠢的问题,但是当我的数据源位于cfm页面时,它可以正常工作,但是当我将数据源放在我的application.cfc中时,它会出错.
来自CFM文件的代码
<cfquery name = "getlist" datasource="jeb48_shoppingcart">
SELECT ProductID, ProductName, ProductQty, ProductPrice, ProductDescription
FROM Products;
</cfquery>
Run Code Online (Sandbox Code Playgroud)
来自CFC的代码
<cfcomponent>
<cfset This.name = "TestApplication">
<cfset This.clientStorage = "jeb48_northwind">
<cfset This.clientmanagement="True">
<cfset This.loginstorage="Session">
<cfset This.sessionmanagement="True">
<cfset This.sessiontimeout="#createtimespan(0,0,10,0)#">
<cfset This.applicationtimeout="#createtimespan(5,0,0,0)#">
</cfcomponent>
Run Code Online (Sandbox Code Playgroud)