Should the Controller be used to extract form data from a dynamic form.

I have a dynamic form… I was wondering if it is considered a good idea to extract the form data within your controller layer?

for(local.i=1 ; local.i <= local.suppliers.recordCount; local.i++){
local.suppliercode = local.suppliers.suppliercode[local.i];
local.formFieldName = ‘local_’ & local.suppliercode;
local.myformvalue = form[local.formFieldName];

}

Or should this extraction/parse logic go elsewhere?

Thanks

Personally I would wrap it up in a function in a service layer or some plugin maybe, nothing wrong with calling it there in the controller, just maybe better if it may be something you will or may use again if it is written as such to begin with.

My rule is, if there is a chance it could be re-used then refactor it to be re-usable.

I see… I didnt think there was anything wrong with doing it this way… But yes it makes sense to abstract it away in its own method so it can be reused.

something like parseFormDataForUpdate

Thanks for your help!

What you could also do, is use interception points to do this automatically as well.

I don’t see why not, but use the rc scope, not the form scope. rc is the proper way to access form and URL variables in ColdBox.

Also, there is a really nifty tool that helps with dynamic form fields called Form Utilities. Basically, you name your form fields as though they are structs or arrays, and this plugin will parse your form fields and actually turn the data into structs and arrays on the server side. Crazy handy for looping over unknown amounts of elements.

Here’s a ColdBox Connection I did once on setting it up:
http://experts.adobeconnect.com/p4qw876231x/

And here’s the sample code to get it working:
http://ortus-public.s3.amazonaws.com/coldbox-connection/cc-formUtilitiesTestApp-02-2013.zip

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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

Thanks everyone for you tips!

great!