开发者

form input element with square bracket

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 variabl开发者_StackOverflow社区e? As a list or an array?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜