本文介绍了kentico通过API添加新的表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Kentico专家您好,

Hello Kentico experts,

我需要通过Kentico API动态创建一些新的表单字段.我找到了一个解决方案,但它适用于Kentico 6,但不适用于我的版本(我使用的是Kentico 8).

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

请帮助!

谢谢,阳

推荐答案

这应该有效:

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);

    }
}

您始终可以在 Kentico DevNet .

这篇关于kentico通过API添加新的表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:53