Disable webhooks on #Episerver forms if not finalized

How to override the default actor to disable none finalized forms to be sent.

icon of user profile

Published 18th of dec 2019
Episerver Forms 2-5

After a visitor submits a form, Forms.Core calls Actors to perform additional processing on the server.

By default, Episerver Forms has two built-in Actors:

  • CallWebhookAfterSubmissionActor
  • SendEmailAfterSubmissionActor

WebHook is a simple event notification via HTTP POST; when a WebHook event is triggered, a HTTP POST request is sent to a URL.

Episerver Forms has built-in WebHooks with the CallWebhookAfterSubmissionActor. As a publisher of the event, WebHooks pushes all form data to the remote URL.

Problem
By default, the Form Step Action Element sends away a webhook action for every step.

Solution
Check the IsFinalized flag by overriding the CallWebhookAfterSubmissionActor. Code below only allows webhooks when forms are finalized.

using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Forms.Core.Models;
using EPiServer.Forms.Core.PostSubmissionActor;
using EPiServer.Forms.Implementation.Actors;
using EPiServer.Forms.Implementation.Elements;

namespace Gosso.Mvc.Business
{
    public class CustomActorsExecutingService : EPiServer.Forms.Core.PostSubmissionActor.ActorsExecutingService
    {
        public override IEnumerable<IPostSubmissionActor> GetFormSubmissionActors(Submission submission, FormContainerBlock formContainer, FormIdentity formIden, HttpRequestBase request, HttpResponseBase response, bool isFormFinalizedSubmission)
        {

            var actors = base.GetFormSubmissionActors(submission, formContainer, formIden, request, response, isFormFinalizedSubmission);
            if (isFormFinalizedSubmission)
                return actors; //return all
            return actors.Where(a => !(a is CallWebhookAfterSubmissionActor));//do not return the webhook actor
        }   
    }
}

And … register the custom actor

private static void ConfigureContainer(StructureMap.ConfigurationExpression container)
{
   container.For<ActorsExecutingService>().Use<CustomActorsExecutingService>();
}

 

Read more:

About the author

Luc Gosso
– Independent Senior Web Developer
working with Azure and Episerver

Twitter: @LucGosso
LinkedIn: linkedin.com/in/luc-gosso/
Github: github.com/lucgosso