kentico add new form field via API

流过昼夜 提交于 2019-12-08 17:40:28

This should work:

string classname = "classname";
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(classname);
if (dci != null)
{
    FormInfo fi = new FormInfo(dci.ClassFormDefinition);
    if (fi != null)
    {
        // Field definition
        FormFieldInfo ffi = new FormFieldInfo();
        ffi.Name = "FieldName";
        ffi.AllowEmpty = true;
        ffi.System = false;
        ffi.FieldType = CMS.FormEngine.FormFieldControlTypeEnum.UploadControl;
        ffi.Visible = true;
        ffi.Caption = "Field Caption";
        ffi.Enabled = true;
        // Set whatever properties are relevant to you

        fi.AddFormItem(ffi);

        TableManager tm = new TableManager(null);
        tm.AddTableColumn(dci.ClassTableName, ffi.Name, "uniqueidentifier", true, null);

        dci.ClassXmlSchema = tm.GetXmlSchema(dci.ClassTableName);
        dci.ClassFormDefinition = fi.GetXmlDefinition();

        // Update DataClassInfo object
        DataClassInfoProvider.SetDataClassInfo(dci);

        // Update inherited classes with new field
        FormHelper.UpdateInheritedClasses(dci);

    }
}   

You can always check the API changes between versions on Kentico DevNet.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!