BizForms API and internals

Database structure

 

Each BizForm has its own database table. You can find its name in the BizForm Properties dialog. This table contains all fields that you specified. You can modify the data using direct access to the database table (there are no dependencies).

 

Custom Field Controls

 

You can create your own field controls as described in chapter Form controls. If you want to make them available in the BizForms field editor, you need to check the box Show control in BizForms in the Form control properties dialog (Site Manager -> Development -> Form controls) and choose the default data type.

 

Event Handling

 

You can run custom actions when a BizForm form is submitted and a record is created, updated or deleted. There are two ways how you can handle the data changes:

 

1. Handling the BizForm control events

 

In this case, you place the BizForm control on a user control or web part and specify the FormName property to the code name of the  required BizForm. Then, you can handle the BizForm events, such as OnAfterSave, OnBeforeValidate, etc.

 

In these handlers, you can access form values using the BizForm.BasicForm.DataRow property and stop further processing (saving) of the form using the BizForm.StopProcessing property. Particular fields, labels and validation error messages can be accessed using properties BizForm.BasicForm.FieldControls, BizForm.BasicForm.FieldLabels and BizForm.BasicForm.FieldErrorLabels.

 

2. Handling global data events

 

You can write a custom data handler as described in chapter Data handler (CustomDataHandler class). Such a handler will allow you to run custom code whenever a database record is inserted, updated or deleted. You can use the dataItem.ClassName property to check if the record being updated is your BizForm code name (you can find the Form code name in the BizForm Properties dialog).

 

Managing data using API

 

The following examples show you how to create, updated and delete form data using .NET code:

 

Creating a new record

 

[C#]

 

using CMS.FormEngine;

using CMS.SettingsProvider;

using CMS.DataEngine;

using CMS.GlobalHelper;

 

...

 

       string bizFormName = "TestingSiteContactUs";

       string siteName = "CMSTestingSite";

 

       // Read BizFrom definition

       BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);

 

       if (bfi != null)

       {

           // Read data type definition

           DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);

 

           if (dci != null)

           {

               GeneralConnection genConn = ConnectionHelper.GetConnection();

               // create a new record in memory (new DataClass object)

               DataClass formRecord = new DataClass(dci.ClassName, genConn);

 

               // 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

               bfi.FormItems++;

               BizFormInfoProvider.SetBizFormInfo(bfi);

           }

       }

 

 

Updating a record

 

[C#]

 

using CMS.FormEngine;

using CMS.SettingsProvider;

using CMS.DataEngine;

using CMS.GlobalHelper;

 

...

 

       string bizFormName = "TestingSiteContactUs";

       string siteName = "CMSTestingSite";

 

       // Read BizForm definition

       BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);

 

       if (bfi != null)

       {

           // Read data type definition

           DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);

 

           if (dci != null)

           {

               // Get all bizform data

               GeneralConnection genConn = ConnectionHelper.GetConnection();

               DataSet ds = genConn.ExecuteQuery(dci.ClassName + ".selectall", null, null, null);

 

               if (!DataHelper.DataSourceIsEmpty(ds))

               {

                   // Get ID of the first record

                   int formRecordID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0][0], 0);

                   // Get the record with ID of the first row record

                   DataClass formRecord = new DataClass(dci.ClassName, formRecordID, genConn);

 

                   if (!formRecord.IsEmpty())

                   {

                       // Set new field values

                       formRecord.SetValue("FirstName", "Bob");

                       formRecord.SetValue("LastName", "Marley");

                       formRecord.SetValue("Email", "bob@email.com");

                       formRecord.SetValue("Message", "Good job:)");

                       formRecord.SetValue("FormUpdated", DateTime.Now);

 

                       // Save updates in the database

                       formRecord.Update();

 

                       lblInfo.Text = "The first record was updated successfully.";

                   }

               }

               else

               {

                   lblInfo.Text = "No data found.";

               }

           }

       }

 

 

Deleting a record

 

[C#]

 

using CMS.FormEngine;

using CMS.SettingsProvider;

using CMS.DataEngine;

using CMS.GlobalHelper;

 

...

 

       string bizFormName = "TestingSiteContactUs";

       string siteName = "CMSTestingSite";

 

       // Get BizForm definition

       BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);

 

       if (bfi != null)

       {

           // Get data type definition

           DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);

           if (dci != null)

           {

               // Get all bizform data

               GeneralConnection genConn = ConnectionHelper.GetConnection();

               DataSet ds = genConn.ExecuteQuery(dci.ClassName + ".selectall", null, null, null);

 

               if (!DataHelper.DataSourceIsEmpty(ds))

               {

                   // Get ID of the first record

                   int formRecordID = ValidationHelper.GetInteger(ds.Tables[0].Rows[0][0], 0);

                   // Get the record with specified ID

                   DataClass formRecord = new DataClass(dci.ClassName, formRecordID, genConn);

 

                   if (!formRecord.IsEmpty())

                   {

                       // Delete the first record.

                       formRecord.Delete();

 

                       // Update number of entries in BizFormInfo

                       bfi.FormItems--;

                       BizFormInfoProvider.SetBizFormInfo(bfi);

 

                       lblInfo.Text = "The record was deleted successfully.";

                   }

               }

               else

               {

                   lblInfo.Text = "No data found.";

               }

           }

       }