Dynamically display form and data with labels

Brenden Kehren asked on June 30, 2014 12:26

I want to dynamically create a form with the labels and values (displayed in labels) for a dynamic class. All I'll have to work with is the class name, no idea on what the field names are, data types or values.

Recent Answers

Joshua Adams answered on June 30, 2014 12:52

Could you create an alternative form through the api? You set the class name, and then you can maybe get the fields you want from the class definition? I haven't had to do that before but maybe that can be an option. Do the data types/fields exist somewhere, or do you have to create those from scratch as well?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 30, 2014 12:55

Thanks Josh.

The classes are all defined in the cms_class table. It's a setup very similar to how biz forms works. Thought maybe there was a control that did something like this already. Seems like a simple task.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on June 30, 2014 13:31

Maybe you could use the DataForm control(part of the CMS.FormControls namespace). There is a property on there to actually set the class name and alternative form if needed. Then you could access individual fields through getting the EditingFormControls. Also, I think there is a property where you can access the labels as well.

using CMS.FormControls;

//create new form based off of class name
DataForm customForm = new DataForm();
//use namespace and then class name(test.testing)
customForm.ClassName = "test.testing";

//fetch editing controls, can set properties on if they aren't null
EditingFormControl testfield1= customForm.FieldEditingControls["testfield1"];
EditingFormControl testfield2= customForm.FieldEditingControls["testfield2"];
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.