This topic provides information on how forms behavior can be modified with your custom code.
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 values of form fields using the BasicForm.GetDataValue(string fieldName) method, which may be called through the corresponding property of the BizForm control. For example: BizForm.BasicForm.GetDataValue("FirstName")
Similarly, the BasicForm.SetDataValue(string fieldName, object value) method allows you to assign field values programatically. If necessary, the data of the entire form may be accessed as a data container through the BizForm.BasicForm.Data property.
You can also stop further processing (saving) of the form by setting the BizForm.StopProcessing property to true. 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.
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).
You can create your own field controls as described in chapter Form controls. If you want to make them available in the form field editor, you need to check the Show control in Forms box in the Form control properties dialog (in Site Manager -> Development -> Form controls) and choose a Default data type.