當我嘗試刪除購物車中的物品時。我收到「元素ID未在表單中定義」錯誤。Coldfusion/SQL:元素ID未在表單中定義
我哪裏錯了?
我使用的是MSSQL 2008 R2,ColdFusion的10
摘要:
tickets.cfm這是顯示產品的頁面,還包含隱藏的值的窗體上cart_manage傳遞.CFM。
cart_manage.cfm是兩個tickets.cfm和cartlist.cfm動作頁
cartlist.cfm是顯示購物車內容的頁面。
application.cfm會話變量。
application.cfm
<cfapplication sessionmanagement="yes">
<cfapplication name="cart" clientmanagement="Yes"
sessionmanagement="Yes"
sessiontimeout="#CreateTimeSpan(0,0,15,0)#"
applicationtimeout="#CreateTimeSpan(0,2,0,0)#">
<cfparam name="session.allowin" default="false">
tickets.cfm
<cfif NOT IsDefined('SESSION.cart')>
<cfset SESSION.cart = ArrayNew(1) />
</cfif>
<cfquery datasource="sqltest" name="getTickets">
select *,
CASE WHEN Friday=1and Saturday=1and Sunday=1
THEN 'All three days'
WHEN Friday=0and Saturday=0and Sunday=0
THEN 'None'
ELSE
STUFF(
case when Friday=1 then ',Friday' else '' end
+ case when Saturday=1 then ',Saturday' else '' end
+ case when Sunday=1 then ',Sunday' else '' end, 1,1,'')
END WhichDays
from tickets_performances;
</cfquery>
<table width="600" border="0">
<tr>
<td>Day</td>
<td>Price</td>
<td>How Many Left</td>
<td>Quantity</td>
</tr>
<p> You can only purchase a maximum of two tickets at a time. Having a ticket limit ensures fairness to all those buying tickets. The ticket limit applies per account, billing address, and/or credit card. Please observe the ticket limit as over purchases may be cancelled without notice or warning. </p>
<cfform action="cart_manage.cfm" name="form" method="post">
<cfoutput query="getTickets">
<tr>
<td>#WhichDays#</td>
<td>£#price#</td>
<td>#stock#</td>
<td><cfinput type="text" id="quantity" name="quantity" size="5" class="field" maxlength="1" value="0"/></td>
<td><cfinput type="hidden" name="id" value="#getTickets.ticket_performanceID#" />
<cfinput type="hidden" name="item" value="#getTickets.WhichDays#" />
<cfinput type="hidden" name="price" value="#getTickets.price#" />
<cfinput type="submit" name="add_button" value="Add to Cart"></td>
</tr>
</cfoutput>
</cfform>
</table>
cart_manage.cfm
<cfset newitem = 0>
<cfloop from="1" to="#arrayLen(session.cart)#" index="i">
<cfif session.cart[i].itemid EQ #form.id#>
<cfset session.cart[i].quantity = session.cart[i].quantity + #form.quantity#>
<cfset newitem = 1>
<cfbreak>
</cfif>
</cfloop>
<cfif newitem EQ 0>
<cfset temp = arrayAppend(session.cart, structNew())>
<cfset session.cart[arrayLen(session.cart)].itemid = #form.id#>
<cfset session.cart[arrayLen(session.cart)].item = #form.item#>
<cfset session.cart[arrayLen(session.cart)].quantity = #form.quantity#>
<cfset session.cart[arrayLen(session.cart)].price = #form.price#>
<cflocation url="cartlist.cfm">
</cfif>
<cfif IsDefined('FORM.delete_button.y')>
<cfloop from="#ListLen(FORM.delete_index)#" to="1" index="i" step="-1">
<cfset ArrayDeleteAt(SESSION.cart, ListGetAt(FORM.delete_index, i))>
</cfloop>
<cflocation url="cartlist.cfm">
<cfelseif IsDefined('FORM.update_button.y')>
<cfloop from="1" to="#ArrayLen(SESSION.cart)#" index="i">
<cfset SESSION.cart[i].quantity = FORM["quantity_" & i] >
</cfloop>
<cflocation url="cartlist.cfm">
<cfelseif IsDefined('FORM.checkout_button.y')>
<cflocation url="checkout.cfm">
</cfif>
<cflocation url="cartlist.cfm">
cartlist.cfm
<cfset nTotal = 0 />
<cfform action="cart_manage.cfm" method="post">
<table width="100%">
<tr valign="top">
<td>
<table width="100%" class="white">
<tr>
<td class="tblehead"> </td>
<td class="tblehead">Item</td>
<td class="tblehead">Price Per Item</td>
<td class="tblehead">Quantity</td>
<td class="tblehead">Price</td>
</tr>
<cfoutput>
<cfloop from="1" to="#ArrayLen(SESSION.cart)#" index="i">
<tr>
<td height="40" width="40" align="center" class="dkturq">
<cfinput type="checkbox" name="delete_index" value="#i#" />
</td>
<td height="40" class="dkturq">
#SESSION.cart[i].item#
</td>
<td height="40" class="dkturq">
£#(SESSION.cart[i].price)#
</td>
<td height="40" class="dkturq">
<cfinput type="text" name="quantity_#i#" value="#SESSION.cart[i].quantity#" size="5" class="field" />
</td>
<td height="40" class="dkturq">
<cfset nPrice = SESSION.cart[i].quantity * SESSION.cart[i].price />
<cfset nTotal = nTotal + nPrice />
£#(nPrice)#
</td>
</tr>
</cfloop>
</cfoutput>
</table>
</td>
<td></td>
<td>
<table width="100%" height="100%" class="white">
<tr>
<td class="tblehead">
Summary
</td>
</tr>
<tr>
<td class="dkturq">
total:
<cfoutput>£#(nTotal)#</cfoutput>
<br /><br /><br /><br />
<a href="clear.cfm">Clear Shopping Cart</a>
<cfinput type="submit" name="update_button" id="update_button" value="update" />
<cfinput type="submit" name="delete_button" id="delete_button" value="delete" /><br /></a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</cfform>
FORM的CFDUMP
Session.cart的CFDUMP
錯誤:
CFDUMP當我按下刪除
什麼頁面發生錯誤?你能發佈確切的錯誤信息嗎? –
步驟1 - cfdump您的表單並驗證id元素是否存在。 –
@ Dan當我添加表單的Cfdump時,我得到以下錯誤:元素ITEMID在作爲表達式的一部分引用的CFML結構中未定義。 –