kentico add new form field via API

点点圈 提交于 2019-12-23 02:26:10

问题


Hello Kentico experts,

I need to create some new form fields dynamically via Kentico API. I found a solution but it is for Kentico 6 and it is not available for my version (i'm using Kentico 8).

https://devnet.kentico.com/articles/how-to-add-a-new-field-to-a-document-type-using-api

Please help !

Thanks, Duong


回答1:


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.



来源:https://stackoverflow.com/questions/43635926/kentico-add-new-form-field-via-api

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