Customize episerver forms cancelled submission message

Vote:
 

Hi, I'm doing some custom validation on server side by attaching an event listener to FormsSubmitting event.

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class FormInitializationModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            FormsEvents formsEvents = ServiceLocator.Current.GetInstance<FormsEvents>();
            formsEvents.FormsSubmitting += OnFormSubmitting;
        }

        private void OnFormSubmitting(object sender, FormsEventArgs e)
        {
            FormsSubmittingEventArgs submitArgs = e as FormsSubmittingEventArgs;
            IEpiFormCustomValidator formValidator = ServiceLocator.Current.GetInstance<IEpiFormCustomValidator>();
            EpiFormCustomValidationResult validationResult = formValidator.Validate(submitArgs.SubmissionData.Data);
            if (!validationResult.IsValid)
            {
                submitArgs.CancelAction = true;
                submitArgs.CancelReason = validationResult.Errors.Select(x => x.Value).FirstOrDefault(); // return first error message
            }
        }

        public void Uninitialize(InitializationEngine context)
        {
            FormsEvents formsEvents = ServiceLocator.Current.GetInstance<FormsEvents>();
            formsEvents.FormsSubmitting -= OnFormSubmitting;
        }
    }

The form is cancelled as expected but the message is quite odd.

Is there any way to replace the whole responsed message (the part inside green circle) instead of just the CancelReason part?

#249508
Mar 03, 2021 8:56
Vote:
 

With the help of Thinh.Truong@episerver.com I'm able to solve this problem by setting up a language file to overwrite content of this path.

Big thank to him.

Additional note: The form's localization file can be found in the EpiServer.Forms.Core.dll file. You can use some reverse engine tool to take a look into that dll and guess which message can be overwritten.

#249511
Edited, Mar 03, 2021 9:51
Vote:
 

The message part inside the green circle is from the <episerver>\<forms>\<messages>\<formsubmission>\<submitcancelled> node of the Forms' embedded language resource file.

Use can override this original string by creating a similar node branch with a desired string, place this node in an existing or a new language resouce file, the <episerver.framework>\<localization node in the web.config file configures the language resource files location, for more information see https://world.episerver.com/documentation/developer-guides/CMS/globalization/localizing-the-user-interface/.

#249513
Edited, Mar 03, 2021 10:01
* 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.