问题描述
目前,有一个表单中的复选框,并在表单提交时所选择的复选框的值存储在数据库中。
Currently, there are checkboxes within a form, and the value of the selected checkboxes are stored in a DB when the form is submitted.
<td><input type="Checkbox" name="valueList" value="Some value, with comma" >Some value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Another Value, with comma" >Another value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Yet another value" >Yet another value</td>
然而,问题是用逗号作为当前逻辑使用的列表来存储这些值。因此,有些价值,用逗号
插入为部分价值
和用逗号
。用以下所创建的当前列表:
However, the issue is with the commas as the current logic uses a list to store these values. So Some value, with comma
is inserted as Some value
and with comma
. The current list is created with the following:
<cfif isDefined("valueList")>
<cfset a=listlen(valueList)>
而code继续通过列表循环。这是唯一的参考 valueList
我能找到在code。有没有办法将其转换为一个数组没有逗号成为一个问题?
And the code continues by looping through the list. This is the only reference to valueList
I could find in the code. Is there a way to convert this to an Array without the commas becoming an issue?
推荐答案
我使用的模式正在取代逗号(,)与因为它不是在我们的领域在所有使用符号(〜),你可以使用任何你想要的字符。
The pattern I use is replacing comma (,) with tilde (~) since it's not used in our domain at all, you can use any character you want.
<td><input type="Checkbox" name="valueList" value="Some value~ with comma" >Some value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Another Value~ with comma" >Another value, with comma</td>
<td><input type="Checkbox" name="valueList" value="Yet another value" >Yet another value</td>
所以,当窗体过来这将是如下:
So when the form comes over it'll be as follows:
form.valueList = "Some value~ with comma, Another Value~ with comma, Yet another value";
这是code得到你想要的数组:
This is the code to get the array you want:
<cfscript>
variables.myArrayList = ListToArray(form.valueList);
for(i=1; i LTE ArrayLen(variables.myArrayList); i=i+1)
{
variables.myArrayList[i] = ReplaceNoCase(variables.myArrayList[i],"~",",","all");
}
</cfscript>
这篇关于ColdFusion表单与数组变量逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!