Skip to main content
Participating Frequently
March 8, 2010
Answered

Accessing form fields with [brackets] in the name

  • March 8, 2010
  • 1 reply
  • 1678 views
Wondering if anyone has ideas for accessing form field values when the fieldnames include brackets like the ones in the cfdump of a form post shown below (it’s a MailChimp webhook)?

When I try to access the values using #form.data[list_id]# for example, I get a ColdFusion error, I’m guessing because it thinks I’m trying to access an array element. Any help appreciated.

struct

DATA[LIST_ID]

000000000

DATA[NEW_EMAIL]

foo@bar.com

DATA[NEW_ID]

000000000

DATA[OLD_EMAIL]

foo@bar.com

FIELDNAMES

TYPE,FIRED_AT,DATA[NEW_ID],DATA[NEW_EMAIL],DATA[OLD_EMAIL],DATA[LIST_ID]  

FIRED_AT

2010-03-08   17:49:09

TEMPID

[empty   string]

TYPE

upemail  

This topic has been closed for replies.
Correct answer Adam Cameron.

One can access struct members either via dot-noation if the keys are "valid variable names", or via bracket notation, eg:

myStruct["myKey"]

Using bracket notation does not have the valid-variable-name restrictions that dot notation has.

--

Adam

1 reply

Adam Cameron.Correct answer
Inspiring
March 8, 2010

One can access struct members either via dot-noation if the keys are "valid variable names", or via bracket notation, eg:

myStruct["myKey"]

Using bracket notation does not have the valid-variable-name restrictions that dot notation has.

--

Adam

tsongasAuthor
Participating Frequently
March 8, 2010

So in the case of my example the correct syntax would be

#form["data[list_id]"]#

correct?

Thanks,

Chris

Inspiring
March 8, 2010

Sure.  Easiest way to find out is to try it...

--

Adam