Implementing dynamic controls and validations in COLDFUSION
Posted on 2010-09-17
This is the scenario I have. I have in my database , in a table, list of fields (like Name, Pin, address) and the validations to be performed on those fields (like limiting the salary to 2 decimal places etc).
These fields are not known at compile time and they are only known at runtime depending on say which user logs in. So for example user A will have fields like Name, address, occupation etc and User B may have fields like CompanyName, Number of Employess etc. Each of these fields have certain set of validations to be performed. For example a fields which is salary, I need to limit the user to only 2 decimal places. These validations need to be done at runtime and not when we submit a page.
This what I have done so far.
1. I make a call to the database to get the fields from the database and put it in a array. each field is stored in a structure. so finally we have an array of structures.
dataEntryFields = ArrayNew(1);
field1 = StructNew();
field1.Name = "Amount";
field1.FieldDataType = "A";
field1.Length = 11;
field1.Justification = "R";
field1.MinAmount = 0.01;
field1.MaxAmount = 100.00;
field1.Message = "Enter Info for Check Amount";
field1.Decimal = 2;
AddIt = ArrayAppend(dataEntryFields,field1);
field2 = StructNew();
field2.Name = "INVNUM";
field2.Prompt = "INVOICE NUMBER :";
field2.FieldDataType = "C";
field2.Length = 7;
field2.Justification = "L";
field2.Message = "ALPHA / NUMERIC; DEROG TEST (USE ALL 9'S AS DEFAULT)";
field2.Decimal = 0;
AddIt = ArrayAppend(dataEntryFields,field2);
That is just one part of the problem. After submitting the page, I need to perform validations on the form values. Since the form fields are dynamic, I need to pass to the response page an array containing the field name and field values. so an array of structure where structure has 2 fields (Name & Value). So what should I do to pass this array from the form page to the submit Page?
I am on coldfusion 9.