Calling a webservice with form data from the page displayed after submission

Vote:
 

I would like to present users with feedback on the result of a webservice call in which data from a form is submitted to the webservice. The most straightforward way to do this seems to be to call the service from the controller for the page displayed after submission (the "thank you page"). The result of the webservice call can then be passed directly to the view for this page. When using an actor this is more complicated.

Two questions:

  1. You can retrieve the form data using the __FormGuid and __FormSubmissionId query string parameters. Where does the form data come from at that point in the process, from the session or from the database?  I have not checked "Store form submissions"!
  2. Is there any reason why you should not go down this road and do the webservice call in an actor instead?

The code I want to use is more or less like this:

    public class ThankYouPageController : PageControllerBase
    {
        public ActionResult Index(ThankYouPage currentPage)
        {
            var formGuid = Request.QueryString["__FormGuid"];
            var languageBranch = Request.QueryString["__FormLanguage"];
            var formSubmissionId = Request.QueryString["__FormSubmissionId"];

            if (!string.IsNullOrEmpty(formGuid))
            {
                var contentRepository = ServiceLocator.Current.GetInstance();
                var formDataRepository = ServiceLocator.Current.GetInstance();
                var formRepository = ServiceLocator.Current.GetInstance();

                var currentForm = contentRepository.Get(new Guid(formGuid));

                if (currentForm != null)
                {
                    var formIdentity = new FormIdentity(new Guid(formGuid), languageBranch);

                    var rawSubmittedData = formDataRepository.GetSubmissionData(formIdentity, new[] {formSubmissionId}).FirstOrDefault();

                    var friendlyNames = formRepository.GetDataFriendlyNameInfos(formIdentity);

                    if (rawSubmittedData != null)
                    {
                        var submittedData = formDataRepository.TransformSubmissionDataWithFriendlyName(
                            rawSubmittedData.Data, friendlyNames, true).ToList();

                        var dataToPost = submittedData.Where(x => x.Key == "DataToPost").Select(x => x.Value).FirstOrDefault()?.ToString();

	            // Call webservice here with dataToPost and present user feedback in the ThankYouPage
						
	            // currentPage.userFeedback = webservice.Result;
                        
                    }
                }
            }

            var model = CreateModel(currentPage);
            return View(model);
        }
}

Submit

[Pasting files is not allowed]

#191156
Edited, Apr 22, 2018 20:40
Vote:
 

Hi,

  1. If you have not choose "Store form submissions", the form data come from Session.
  2. Not sure I understand you question correctly. Using actor to call external service is an official way, you can run it sync or async with submitting process. But to use the call result as an input for your display "Thank you" page, you need to have some overriding default be haviour. If the above code satisfy your requirements, just use it anyway.
#191211
Apr 24, 2018 9:14
Vote:
 

Hi,

Thanks for your reply. Regarding the second question, the code satisfies my requirements quite well, but I was trying to make sure it falls within the regular way of doing things with Episerver Forms, which will still be working in future versions.

#191214
Apr 24, 2018 9:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.