|
||
The sample code below demonstrates how a new record can be added to a form using the API.
[C#]
using CMS.FormEngine; using CMS.SettingsProvider; using CMS.DataEngine; using CMS.GlobalHelper;
...
string bizFormName = "TestingSiteContactUs"; string siteName = "CMSTestingSite";
// Read From definition BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);
if (bfi != null) { // Read data type definition DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);
if (dci != null) { BizFormItemProvider bProvider = new BizFormItemProvider(); // Create a new record in memory BizFormItem formRecord = new BizFormItem(dci.ClassName, bProvider);
// Insert some data formRecord.SetValue("FirstName", "Alice"); formRecord.SetValue("LastName", "Cooper"); formRecord.SetValue("Email", "alice@email.com"); formRecord.SetValue("Message", "Hallo world"); formRecord.SetValue("FormInserted", DateTime.Now); formRecord.SetValue("FormUpdated", DateTime.Now);
// Insert the new record in the database formRecord.Insert();
// Update number of entries in BizFormInfo BizFormInfoProvider.RefreshDataCount(bfi.FormName, bfi.FormSiteID); } } |