Take the community feedback survey now.

Nahid
Jul 16, 2024
  1436
(1 votes)

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default, the submitted data is stored and can be exported in different formats. Additionally, it has two other default actors: email and webhook, which are helpful for sending emails as well as webhooks.

default actor preview

However, sometimes clients want to use their own third-party development to integrate and save/post API data. This is where custom actors come into play. In this blog, we'll learn how to create custom actors and how to integrate them with APIs. Let's get started!

Custom Actor Model

To create a custom actor, we first need to create a class that inherits from IPostSubmissionActorModel and ICloneable. This class is used for the actor definition. In this example, we'll use two actor models in the dropdown list: one for Survey and another for Registration. You can use selection based on your requirements. Also, note that this model should be serializable.

public class CustomActorModel : IPostSubmissionActorModel, ICloneable
{
    [Display(Name = "Actor Type", Order = 101)]
    [SelectOne(SelectionFactoryType = typeof(CustomActorTypeFactory))]
    public virtual string ActorType { get; set; }

    public object Clone()
    {
        return new CustomActorModel
        {
            ActorType = this.ActorType
        };
    }

    private class CustomActorTypeFactory : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            return new ISelectItem[]
            {
                new SelectItem() { Text = "Survey API", Value = "1" },
                new SelectItem() { Text = "Registration API", Value = "2" }
            };
        }
    }
}

Editor Descriptor

After creating the custom actor model, you need to inject this into the editor descriptor, which is used to render the grid UI. For this, you need to inherit an editor descriptor class using the Dojo widget CollectionEditor to render.

[EditorDescriptorRegistration(TargetType = typeof(IEnumerable<CustomActorModel>), UIHint = "ConfigurableActorPropertyHint")]
public class CustomActorEditorDescriptor : CollectionEditorDescriptor<CustomActorModel>
{
    public CustomActorEditorDescriptor()
    {
        ClientEditingClass = "epi-forms/contentediting/editors/CollectionEditor";
    }
}

Property Definition

After creating the editorial descriptor, you need to add a property definition for this actor model and inject the editorial hint from the editorial descriptor

[EditorHint("ConfigurableActorPropertyHint")]
[PropertyDefinitionTypePlugIn(DisplayName = "ConfigurableActorProp")]
public class PropertyForDisplayingCustomActor : PropertyGenericList<CustomActorModel>
{
}

Custom Actor

The final part involves implementing the custom actor, which inherits from PostSubmissionActorBase and implements the interface IUIPropertyCustomCollection. The PostSubmissionActorBase will override the Run method where our custom implementation will be done, and IUIPropertyCustomCollection will be used for the edit view user interface of configuring the actor model.

Here, PropertyType will be our custom property type name.

Below is a sample implementation of the Run method where we inject formDataRepository. We take the submitted data and find the data based on the element name. We create a custom method that will get the value based on the element name. As you can see, we can use CancelSubmit and ErrorMessage on the result response to prevent data submission as well.

public class CustomActor : PostSubmissionActorBase, IUIPropertyCustomCollection
{
    private readonly Injected<IFormDataRepository> _formDataRepository;

    public override object Run(object input)
    {
        var result = new SubmissionActorResult { CancelSubmit = false, ErrorMessage = string.Empty };
        var configs = (Model as IEnumerable<CustomActorModel>);
        var submittedData = _formDataRepository.Service.TransformSubmissionDataWithFriendlyName(SubmissionData.Data, SubmissionFriendlyNameInfos, true).ToList();

        if (configs.Any() && configs.Select(ap => ap.ActorType).FirstOrDefault() == "1") // Survey
        {
            // Get by form element name
            var nameData = GetValueByKey(submittedData, "name");
            // Implement your API
            // If success, then just return result;
            // If not successful, then:
            result.CancelSubmit = true;
            result.ErrorMessage = "your message";
        }
        else if (configs.Any() && configs.Select(ap => ap.ActorType).FirstOrDefault() == "2") // Registration
        {
            // Follow the previous comment
        }
        else
        {
            return result; // It'll call other actors if it has any;
        }
        return result;
    }

    public virtual Type PropertyType => typeof(PropertyForDisplayingCustomActor);

    private string GetValueByKey(List<KeyValuePair<string, object>> list, string key)
    {
        var item = list.FirstOrDefault(kvp => kvp.Key == key);
        return item.Value?.ToString();
    }
}

Now, if you run your project, you will see that the custom actor has been displayed in your form, and you can select any of them. Based on the selection, when you submit the form, your custom actor will be invoked.

custom actor preview

Jul 16, 2024

Comments

Please login to comment.
Latest blogs
Optimizely CMS Mixed Auth - Okta + ASP.NET Identity

Configuring mixed authentication and authorization in Optimizely CMS using Okta and ASP.NET Identity.

Damian Smutek | Oct 27, 2025 |

Optimizely: Multi-Step Form Creation Through Submission

I have been exploring Optimizely Forms recently and created a multi-step Customer Support Request Form with File Upload Functionality.  Let’s get...

Madhu | Oct 25, 2025 |

How to Add Multiple Authentication Providers to an Optimizely CMS 12 Site (Entra ID, Google, Facebook, and Local Identity)

Modern websites often need to let users sign in with their corporate account (Entra ID), their social identity (Google, Facebook), or a simple...

Francisco Quintanilla | Oct 22, 2025 |

Connecting the Dots Between Research and Specification to Implementation using NotebookLM

Overview As part of my day to day role as a solution architect I overlap with many clients, partners, solutions and technologies. I am often...

Scott Reed | Oct 22, 2025

MimeKit Vulnerability and EPiServer.CMS.Core Dependency Update

Hi everyone, We want to inform you about a critical security vulnerability affecting older versions of the EPiServer.CMS.Core  package due to its...

Bien Nguyen | Oct 21, 2025

Speeding Up Local Development with a Fake OpenID Authentication Handler

When working with OpenID authentication, local development often grinds to a halt waiting for identity servers, clients, and users to be configured...

Eric Herlitz | Oct 20, 2025 |