带方括号的表单输入元素
在我的表单中,我有一个带方括号的元素:
<input name="bodyIDList[]" id="bodyIDList" value="">
当我将此页面传递给 ColdFusion 时,如何将其视为表单变量?作为列表还是数组?
In my form I have an element with square bracket:
<input name="bodyIDList[]" id="bodyIDList" value="">
When I pass this page to ColdFusion how is this treated as a form variable? As a list or an array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道你为什么问这个问题 - 创建一个测试并亲自找出答案实际上需要几秒钟!
测试它的代码很简单:
运行它,按 go,查看转储。
但是,既然我们现在在这里提出了这个问题,我不妨给出一个完整的答案,因为实际上有一件有趣的事情需要注意......
如果您在 Adobe ColdFusion 9(或任何其他版本的CF) 您将获得一个名为
bodyIDList[]
的字符串变量 - 即Form['bodyIDList[]']
- 具有单个值。如果您有多个这些字段,您仍然会得到一个带有逗号分隔列表的字符串。
由于变量名中包含括号,因此无法使用点表示法访问该字段。
上述所有内容也适用于最新的 Open BlueDragon。
但是,如果您使用 Railo,您将得到不同的行为(从 PHP 复制),它会给您一个变量称为
bodyIDList
- 即没有括号的 Form['bodyIDList'] - 包含一个数组如果您有多个这些字段,您将得到一个包含多个元素的数组。
目前没有管理配置选项可以使 Railo 与 ACF 兼容,因此:
如果您正在编写跨引擎 CFML 代码,请勿使用带括号的表单字段名称。
(好吧,除非您意识到并愿意处理这些差异)。
Not sure why you are asking this question - it takes literally a few seconds to create a test and find out for yourself!
The code to test it is this simple:
Run that, press go, look at the dump.
But, since we've now got this question here, I might as well give a full answer, since there is actually an interesting thing to be aware of...
If you run that code on Adobe ColdFusion 9 (or any other version of CF) you will get a string variable named
bodyIDList[]
- that isForm['bodyIDList[]']
- with a single value.If you had multiple of these fields you will still get a string with a comma-delimited list.
Since it contains brackets in the variable name, it is not possible to access this field with dot-notation.
All the above also applies for the latest Open BlueDragon.
However, if you use Railo, you will get a different behaviour (copied from PHP) which instead will give you a variable called
bodyIDList
- i.e. Form['bodyIDList'] with no brackets - which contains an arrayIf you had multiple of these fields you would get a single array with multiple elements.
There is currently no admin configuration option to make Railo compatible with ACF on this, so:
If you are writing cross-engine CFML code, do not use form field names with brackets.
(well, unless you're aware and willing to deal with the differences).
该元素将单独列出,例如作为 bodyIDList[]。我刚刚在我的一台 CF9 盒子上检查了这一点。
现在,如果您有多个同名字段,它将在表单范围中显示为列表。
The element will be listed individually, e.g. as bodyIDList[]. I just checked this on one of my CF9 boxes.
Now, if you had multiple fields of the same name, it would appear as a list in the form scope.