ColdFusion Preserve POST variable name case


ColdFusion provides access to POSTed data via the FORM structure. Unfortunately ColdFusion always upper-cases the names of these variables. Recently a chunk of code I was working on needed to know the original case of these keys. At first I worked on passing a hidden form field with the original field name text, but this bothered me as way too much of a work-around.

This chunk of code will give you a structure called FormContent where the case of the field names is preserved.

Unfortunately this code will not distinguish between two fields with the same name but different case. To do that, you’ll want to use a case-sensitive StructNew() alternative. I recommend CreateObject(”java”, “java.util.LinkedHashMap”).init(). This has the added value of preserving the order that the fields appeared in the calling form when you iterate over it for output. It has the disadvantage that you’ll have to properly match case of the keys when you retrieve them in your code.

  1. #1 by Brian at April 2nd, 2008

    When would you need to worry about case sensitivity?

  2. #2 by eric stevens at April 2nd, 2008

    I did recently when I was dynamically generating fields whose name contained a varchar primary key from an Oracle database.

  3. #3 by Brian at April 3rd, 2008

    Ah, now I see.

  4. #4 by Andrew Roazen at May 12th, 2009

    This was a last minute lifesaver (writing a template to convert form submissions to XML). Thanks.

(will not be published)
  1. No trackbacks yet.