带方括号的表单输入元素

发布于 2024-12-03 10:45:57 字数 163 浏览 0 评论 0原文

在我的表单中,我有一个带方括号的元素:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-12-10 10:45:57

不知道你为什么问这个问题 - 创建一个测试并亲自找出答案实际上需要几秒钟!

测试它的代码很简单:

<cfoutput>
    <form action="#CGI.SCRIPT_NAME#" method="post">
        <input name="bodyIDList[]" id="bodyIDList" value="">
        <button type="submit">go</button>
    </form>
</cfoutput>

<cfdump var=#Form# />

运行它,按 go,查看转储。

但是,既然我们现在在这里提出了这个问题,我不妨给出一个完整的答案,因为实际上有一件有趣的事情需要注意......

如果您在 Adob​​e 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:

<cfoutput>
    <form action="#CGI.SCRIPT_NAME#" method="post">
        <input name="bodyIDList[]" id="bodyIDList" value="">
        <button type="submit">go</button>
    </form>
</cfoutput>

<cfdump var=#Form# />

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 is Form['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 array

If 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).

煞人兵器 2024-12-10 10:45:57

该元素将单独列出,例如作为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文