Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Redirect user from custom actor to dynamically generated URL

mh
mh
Vote:
 

Hello!

We would like to have a custom actor which dynamically generates a URL which we want browser to redirect user to after posting. How would we go about achieving this?

In this documentation https://world.episerver.com/documentation/developer-guides/forms/implementing-a-customized-actor/ I only find the following information: 

Actors must return an object instance of a class which implements EPiServer.Forms.Core.PostSubmissionActor.Internal.ISubmissionActorResult.
By implementing this interface, the returned result will have two properties:

  • CancelSubmit (boolean): determines whether the form submission should be canceled or not.
  • ErrorMessage (string): this error message will be displayed to visitors.
#198766
Nov 06, 2018 14:01
Vote:
 

Hi mh,

If you only want to dynamically generate an URL and then redirect user to that URL you just need to override BuildReturnResultForSubmitAction method of DataSubmissionService class. The example below will redirect browswer to google site after submission. 

// Dependency

context.Services.AddTransient<DataSubmissionService, CustomDatasubmissionService>();
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 = "")
    {
        var baseResult = base.BuildReturnResultForSubmitAction(isJavaScriptSupport, isSuccess, message, httpContext, formContainer, additionalParams, submissionInfo, submission, isProgressiveSubmit, redirectUrl);
        if (isSuccess) // only set redirect url when sucesss
        {
          // generate your own URL
          baseResult.RedirectUrl = "http://google.com";
        }

        return baseResult;
    }
}
#198803
Edited, Nov 07, 2018 7:59
Vote:
 

ISubmissionActorResult and ISyncOrderedSubmissionActor are available from Forms version 4.16. There may be several actors (both built-in and custom actors) will be run along with submission process. ActorsExecutingService is responsible for triggering all actors while submitting form.

1. Actors implementing ISyncOrderedSubmissionActor interface will be run first. If there are many instanace of this interface, they will be run in ascending order. SaveDataToStorageActor is one built-in actor implement this interface. SaveDataToStorageActor is responsible for saving data to storage and it has Order = 1000. So if you want to have another actor run before saving data to storage, that actor should implement ISyncOrderedSubmissionActor and set Order < 1000

2. Asynchronous actors (actors with IsSyncedWithSubmissionProcess is set to false) will be run (e.g built-in actor CallWebhookAfterSubmissionActor & SendEmailAfterSubmissionActor)

3. Synchronous actors (actors with IsSyncedWithSubmissionProcess is set to true) will be run. 

#198804
Edited, Nov 07, 2018 8:18
mh
Vote:
 

Thanks for your reply, I will try this.

#198834
Nov 07, 2018 12:59
Vote:
 

why would you register service explicitly in service collection and at the same time use ServiceConfiguration attribute?

#198835
Nov 07, 2018 13:50
Vote:
 

hi Valdis,

Yes you're right, no need to use ServiceConfiguration attribute. I Edited the code.

#198869
Nov 08, 2018 2:29
* 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.