Submitting and accessing a Sub Array on form submission

I am trying to submit and access a subset of a form submitted, in a similar way as with nested forms can be done in rails and (from memory) with cfwheels.

In rails and wheels, a form inputs name can be “address[town]”. This can then be accessed as an array called ‘address’ when the form is submitted.

For example, I have the following fields:

`


`

When I then submit this form, I want to be able to access each address as seperate objects with #rc.address1# and #rc.address2#, but I get an error that address1 does not exist in rc

With rails and cfwheels, a form can bee accessed this way with params.address1 and params.address2. Does anyone know if there is any way in Coldbox to be able to pass and receive a form in this manner?

Thanks!

Jason

Have you seen Brian Kotek’s FormUtilities plugin? I believe it does something to this effect.

I thought it was on ForgeBox, but I couldn’t find it. Here are some links to get you started, though:

http://formutils.riaforge.org/

http://objectivebias.com/entry/formutilities-plugin-for-coldbox

http://vimeo.com/59699684

What do you see when you dump out rc? Are you using the Form Utilities plugin?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yes, really need to wrap this up as a nice module and put it on Forgebox. Any takers? All it needs is a model and an interceptor!

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Joel/Brad,

No, I am not using the Form Utils plugin… but will check that out now.

Brad, when I dump out rc, I see:

address1[street]
address1[town]

address1[postcode]

address2[street]
address2[town]

address2[postcode]

if I dump out rc.address1, I get an error that address1 doesn’t exist in rc.

Will check out the formUtils plugin and let you know how I go.

Thanks!

Well, that would be correct then. ColdBox doesn’t do any automatic parsing of specially-named form or URL fields. The rc struct presents the variables to you the same way they would show up in the form or URL scope.

The Form Utilities plugin will get you want you need. In fact, it’s probably what CFWheels uses. The third link Joel posted is a video where I show exactly how to set it up in your application.

Actually, click this link:
http://www.coldbox.org/media/connection

and look at the third from the top recording. It’s the same thing, but with links to sample code as well :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

If you use dot-notation, rather than associative array notation, Railo will do this by default for you.

I think ColdFusion 10 added support for this with dot notation as well, but not 100% certain.

Brad, your interceptor video gave me exactly what I needed. Thank you ! Viva La Coldbox!!

Andrew, dev box is CF10, but wasn’t converting. Not sure if it’s a setting(?) But my experience with cf10 is that dot notation in forms is not converting to struct.

Thanks all!

Jason

Yeah I was guessing, Adobe to make changes to what and how something is passed, to the point it broke a lot of things when it was first released. I know it had something to do with how forms are passed into ColdFusion… It had something to do with arrays.

I think the CF10 thing is the sameFormFieldsAsArray setting. When set to true, it will array-ify values from any form fields that have the same name.

hmm, yeah thought so. I was going by memory on that anyway.

I’ve just added a formutilities module that wrap Brian’s plugin. However this does not work with form like: myaddress[home]