4

How can you disable the sameformfieldsasarray when you have an Application.cfm file?

I'm porting a legacy application from ColdFusion 9 to ColdFusion 10. The site uses an old school Application.cfm file.

I see that 10 added a new setting (this.sameformfieldsasarray) that you can enable that will combine form variables into an array when there is more than one of them. This is supposed to be off by default, but unfortunately it's "on" for the fresh installation I just set up.

I can't set this.sameformfieldsasarray false because we've got Application.cfm instead of Application.cfc, and I can't find anything in the admin or documentation.

The code is run from a fresh install of CF10 on Ubuntu 12.04 x64. @Adam verified that the sample code worked on Windows Server 2003 x64.


Code: https://gist.github.com/2931343

Screenshot of sample submit: https://i.stack.imgur.com/mNRsY.jpg

Screenshot of server scope: https://i.stack.imgur.com/WWHih.jpg

Bug report submitted: https://bugbase.adobe.com/index.cfm?event=bug&id=3214734

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Joe Zack
  • 3,268
  • 2
  • 31
  • 37
  • 1
    I am a little curious *why* it is enabled. Silly question, but are you sure there is not an `Application.cfc` that is being called instead? Because in my tests the default is `false`. – Leigh Jun 13 '12 at 21:59
  • If you're porting to CF10, you can port your App.cfm to an App.cfc too. – Peter Boughton Jun 13 '12 at 23:20
  • It's a horrible app, and re factoring the app.cfm is not feasible. I'm sure there is no Application.cfc here, and I've searched for the setting name throughout the codebase. It's on by default. – Joe Zack Jun 14 '12 at 13:41
  • Query - how did you discover this existed? – Raymond Camden Jun 14 '12 at 21:57
  • I've got a legacy app that abuses multiple form fields with the same name. I wanted to upgrade the app to CF10, so I provisioned a new machine, installed cf10, and dropped the app in to test. I ran into the issue almost immediately because of the (ill) nature of the app. – Joe Zack Jun 15 '12 at 14:52
  • @JoeZack - Was anyone else running *nix able to duplicate the issue ie confirm the same results? (I am on windows) Also, is it enabled by default for all Application.cfc files as well? – Leigh Jun 15 '12 at 17:35
  • I haven't tried to verify it on any other *nix boxes, it was NOT on for the Application.cfc file. – Joe Zack Jun 18 '12 at 21:13

3 Answers3

3

I'm not sure about this one. CF 10 is so new that you are probably the first person to ask this question in public (ha). But perhaps you could do the following in your application.cfm.

<cfloop collection="#form#" item="fitem">
    <cfif isArray(form[fitem])>
        <cfset form[fitem] = arraytolist(form[fitem])/>
    </cfif>
</cfloop>

That would set things right I suspect.

Loftx
  • 1,760
  • 4
  • 29
  • 50
Mark A Kruger
  • 7,183
  • 20
  • 21
  • I'd hate to resort to that, but it's looking to bemy only option. Thanks! – Joe Zack Jun 13 '12 at 21:41
  • Something is not adding up here... because the default is definitely false. Did you run a test in a separate directory (with no other Application files in its path)? – Leigh Jun 14 '12 at 07:05
  • Agree with Leigh: it's OFF by default. So if it's ON... you've switched it on. Are you sure you didn't switch it on when testing something, and the app has not since been restarted? – Adam Cameron Jun 14 '12 at 07:58
  • I'm sure, I have no way of switching it on. I just did a fresh install on a new machine, dropped the app in and it started breaking. – Joe Zack Jun 14 '12 at 12:32
  • OK, how are you seeing that it's ON? Is it because the form scope suddenly has arrays in it, or are you seeing it if you dump out getApplicationMetadata() (or some other way)? Also, can you post your tag from your Application.cfm – Adam Cameron Jun 14 '12 at 14:16
  • I'm seeing the form scope with arrays in it, getApplicationMetadata returns an empty struct. – Joe Zack Jun 14 '12 at 14:59
  • 1
    There's no way you should get an empty struct if you're running the test in the scope of that `` tag. The only way I can get an empty struct is if I have NO `` tag at all. Are you CERTAIN there's no Application.cfm between where you're running this code and where that `` is? – Adam Cameron Jun 14 '12 at 15:11
  • My apologies, I dumped it before the cfapplication tag. I do not see the sameformfieldsasarray setting in the resulting struct, but the values are still getting converted. – Joe Zack Jun 14 '12 at 16:19
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12567/discussion-between-adam-cameron-and-joe-zack) – Adam Cameron Jun 14 '12 at 16:24
  • I am experiencing the same issue and have tested the fix by Mark A Kruger - this works fine in my legacy application though I have tidied the formatting. – Loftx Jul 26 '12 at 15:12
2

This issue is now resolved in ColdFusion 10 Update 1 which was released on 31st August 2012.

Applying the update should resolve the issue and allow workarounds such as the one suggested by Mark A Kruger to be removed.

Loftx
  • 1,760
  • 4
  • 29
  • 50
0

I realize this post is nearly a dozen years old, but it came up in a search today about this feature, and I wanted to propose an answer that I don't see anyone else having offered--and it seems the exact resolution to the original problem, albeit surely too late for the OP/Zack. :-)

He's said:

I can't set this.sameformfieldsasarray false because we've got Application.cfm instead of Application.cfc, and I can't find anything in the admin or documentation.

It's indeed true that sadly, most docs and resources mentioning this sameformfieldsasarray feature (and other features that can be set in the this scope of an application.cfc) tend to not mention how nearly all of them can be set simply as attributes of cfapplication as well.

<cfapplication sameformfieldsasarray="false"> (or true, if desired)

But yep, there was indeed a problem originally that it defaulted to true, which was fixed in CF10 update 1. The same problem happened again with CF2018 update 11 and CF2021 update 1--but the default reverted to true again in CF2018 update 12 and CF2021 update 2.

charlie arehart
  • 6,590
  • 3
  • 27
  • 25