Jolly Good Websites for Reading Businesses Established October 1999
Tel. 0845 6445513 (national) Tel. 0118 9507617 (local)

Tuesday, 28 June 2011

Quirk Converting Coldfusion to Railo

This is a neat and useful bit of code I've been using for about a decade to handle the output from a form in Coldfusion:

<CFLOOP FROM="1" TO="#ListLen(form.fieldnames)#" INDEX="y">
#ListGetAt(form.fieldnames,y)# = #Evaluate(ListGetAt(form.fieldnames,y))#<br />
</CFLOOP>


Within the loop, I usually do something like this to check for a particular field name so that I can do error-checking or something:


<cfif find("FIRST_NAME", #ListGetAt(form.fieldnames,y)#) gt 0>
... some code ...
</cfif>


In Coldfusion, the value of form.fieldnames would always be in capitals, even if the original HTML form had all the field names in lower case.

But since I've started working with Railo, I've found that this doesn't work the same. The loop works, but Railo doesn't recognise "FIRST_NAME" if the HTML on the page was written as "first_name".

So, if you want to check for a particular field name without knowing for sure if the original field name was written in upper or lower case, you have to do something like this...


<cfif find("FIRST_NAME", #ListGetAt(UCASE(form.fieldnames),y)#) gt 0>
... some code ...
</cfif>


On balance, I'd say Railo works the way you'd expect. Better men than me probably know why Coldfusion has always converted fieldnames to caps. Before you start writing - I don't really need to know.