Kentico CMS 7.0 Developer's Guide

Customization possibilities

Customization possibilities

Previous topic Next topic Mail us feedback on this topic!  

Customization possibilities

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

This topic provides information on how forms behavior can be modified with your custom code.


Event Handling


You can run custom actions when a form record is created, updated or deleted. There are two ways how you can handle these events:


1. Handling BizForm control events


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


In these handlers, you can retrieve the values of form fields using the BasicForm.GetFieldValue(string fieldName) method, which may be called through the corresponding property of the BizForm control. For example:






The data of the entire form may be accessed as a data container through the BizForm.BasicForm.Data property. This allows you to insert values into fields programatically using the SetValue(string fieldName, object value) method. For example:




BizForm.BasicForm.Data.SetValue("TimeStamp", DateTime.Now);


Please note that field values need to be set at the appropriate time in the BizForm control's life cycle. A suitable place is in the handler of the OnBeforeSave event.


If you wish to set up special behavior in the form during the editing process, individual controls that make up the fields, labels and validation error messages in the form can be accessed through the hash tables provided by the BizForm.BasicForm.FieldControls, BizForm.BasicForm.FieldLabels and BizForm.BasicForm.FieldErrorLabels properties.


If necessary, you can stop further processing (saving) of the form at any point by setting the BizForm.StopProcessing property to true.


An example of this type of customization can be found in Development -> Web parts -> Modifying web parts -> Modifying code of standard web parts.


2. Handling global data events


You can write a custom data handler as described in the API programming and Kentico CMS internals -> Data handler (CustomDataHandler class) topic. This type of 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 matches the code name of your form (you can find it in the Form code name field on the General tab of a form's editing interface).


Custom field controls


You can create your own field controls as described in the Form controls chapter. If you want to make a form control available in the field editor of the Forms module, you need to check the Show control in Forms box in the given control's editing dialog (in Site Manager -> Development -> Form controls) and also choose a Default data type. To ensure that the form control is also offered in the simple mode of the form field editor, it is also necessary to enable its High priority flag.