Try our conversational search powered by Generative AI!

Forms - Customise "Display message after form submission"

Vote:
 

Hi,

I need to customise the "Display message after form submission" displayed to a user after submitting a form using EPiServer Forms. I have a message set already and I need to add a unique reference number to this message for the user once the form is submitted.

I see there is a DataSubmissionService which has a FormsSubmissionFinalized event, is this the best thing to use? If so, how do I implement this? I can't see anything obvious. Are there any other approaches?

Thanks in advance,

Mark

#150507
Jun 21, 2016 12:42
Sam
Vote:
 

Me too

#216527
Feb 07, 2020 15:21
Vote:
 

Hi Sam,

You were probably better off starting a new thread opposed to dredging up one that was this old!

Regardless, you can't use the FormsSubmissionFinalized event. What you'll need to do is add a custom DataSubmissionService (EPiServer.Forms.Core.Internal) implementation and override the BuildReturnResultForSubmitAction method, as per this example:

public class CustomDataSubmissionService : DataSubmissionService
{
    protected override SubmitActionResult BuildReturnResultForSubmitAction(bool isJavaScriptSupport, bool isSuccess,
        string message, HttpContextBase httpContext, FormContainerBlock formContainer = null,
        Dictionary<string, object> additionalParams = null, SubmissionInfo submissionInfo = null,
        Submission submission = null, bool isProgressiveSubmit = false, string redirectUrl = "")
    {
        if (!string.IsNullOrEmpty(message))
        {
            message = $"{message}<p>Example.</p>";
        }

        return base.BuildReturnResultForSubmitAction(isJavaScriptSupport, isSuccess, message, httpContext,
            formContainer, additionalParams, submissionInfo, submission, isProgressiveSubmit, redirectUrl);
    }
}

You can easily switch out the default implementation:

[InitializableModule]
public class FormsInitialization : IConfigurableModule
{
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.ConfigurationComplete += (o, e) =>
        {
            context.Services.AddSingleton<DataSubmissionService, CustomDataSubmissionService>();
        };
    }

    public void Initialize(InitializationEngine context)
    {
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}

This will append "<p>Example.</p>" to the end of your success message (regardless of the form or the message) but it hopefully gives you enough to get started.

#217155
Feb 18, 2020 18:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.