方括号中的HTML表单数组。只是传统​​的或与意义? [英] Square brackets in HTML form arrays. Just conventional or with a meaning?

查看:293
本文介绍了方括号中的HTML表单数组。只是传统​​的或与意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常看到,特别是在PHP世界,下一个写,如果你想创建一个表单数组。

I frequently see, in particular in the PHP world, the following writing if you want to create a FORM array.

<input name="MyArray[]" />
<input name="MyArray[]" />

用方括号[]。尽管如此,提交操作只是传递相同的密钥输入两次。看来,[]仅仅是传统的很好的映射到PHP世界阵列,但你只获得同样的结果以下

with the square brackets []. Nevertheless, the submit operation just passes the same key entry twice. It appears that the [] is just conventional that maps nicely to the PHP world array, but you would obtain the same result with just the following

<input name="MyArray" />
<input name="MyArray" />

事实上,在Django我得到两个项的列表,无论使用何种风格。

Indeed, in django I get a list of two entries, regardless of the style used.

这是真的吗?是[]只是常规的,或者实际上有一个真正意义上把它从HTML和HTTP键/值信息?

Is this true ? Are the [] just conventional, or there's actually a real meaning into it from the HTML and HTTP key/value info ?

推荐答案

他们解决PHP的限制,不产生一个数组,如果自动与多个同名的值被提交,例如从一组复选框或多选。 (IIRC它只返回最后一个值。)

They address a limitation of PHP, which doesn't generate an array automatically if multiple values with the same name are submitted, for example from a set of checkboxes or a multiple select. (IIRC it only returns the last value.)

我个人一直认为它是一个pretty以次充好的解决方法。即使是经典ASP可以与应付,无需客户端增加的标记。服务器端平台没有经营这种方式在客户端上施加标记的要求。

Personally I've always thought it to be a pretty shoddy workaround. Even Classic ASP could cope with that without requiring client-side additions to markup. The server-side platform has no business imposing markup requirements on the client in this way.

这篇关于方括号中的HTML表单数组。只是传统​​的或与意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆