custom form event handler

lawrence whittemore asked on January 6, 2025 19:01

I'm struggling to get a form handler working. I have the same code listed in the documents, in the "old app code" folder, and when I start the site, I am able to hit breakpoints set in this section

using System;

using CMS;
using CMS.DataEngine;
using CMS.EmailEngine;
using CMS.OnlineForms;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(FormHandlerModule))]

public class FormHandlerModule : Module
{
    // Module class constructor, the system registers the module under the name "CustomFormHandlers"
    public FormHandlerModule()
        : base("CustomFormHandlers")
    {
    }

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()
    {
        base.OnInit();

        // Assigns a handler to the BizFormItemEvents.Insert.After event
        // This event occurs after the creation of every new form record
        BizFormItemEvents.Insert.After += FormItem_InsertAfterHandler;
    }

But anything after this isn't hit when a form is submited.

private void FormItem_InsertAfterHandler(object sender, BizFormItemEventArgs e)
{
    // Gets the form data object from the event handler parameter
    BizFormItem formDataItem = e.Item;

    // Checks that the form record was successfully created
    // Ensures that the custom actions only occur for records of the 'ContactUs' form
    // The values of form class names must be in lower case
    if (formDataItem != null && formDataItem.BizFormClassName.Equals("bizform.hussonfamilyandhussoninternaltimeOffrequest", StringComparison.OrdinalIgnoreCase))
    {... rest of the code

Recent Answers


Juraj Ondrus answered on January 7, 2025 05:13 (last edited on January 9, 2025 08:55)

Is the code hit if you add it into the other class which is working? I would also recommend using a separate assembly as recommended in the documentation. And make sure you are using this custom class on the app where given action takes place. Admin vs. front end app.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.