Display xform data in ThankYou Page


I want to display submitted Xform Data in redirected page or ThankYou Page

Oct 29, 2015 18:13

If you're using the redirected page function in xforms there are no good way to do so since it makes a normal redirect.

I would suggest that you override that part in the xform handling and add a reference to the posted data as query string and redirect.

on the thank you page you could have a speck fix page type or a block capable to read the posted data.

are you using MVC or Webforms?

Oct 30, 2015 7:30

I am using webforms.

How to read the Posted data in the page or block.. 

Oct 30, 2015 17:51

Managing redirect

In the frontend use 

<EPiServer:XFormControl id="XFormControl" runat="server" />

And in the backend apply the form and hook up to the AfterSubmitPostedData event to get the form information in OnInit.

        protected override void OnInit(EventArgs e)

            XForm xForm = CurrentBlock.Form;
            this.XFormControl.FormDefinition = xForm;
            this.XFormControl.AfterSubmitPostedData += XFormControlOnAfterSubmitPostedData;

        private void XFormControlOnAfterSubmitPostedData(object sender, SaveFormDataEventArgs saveFormDataEventArgs)
            XFormData xFormData = saveFormDataEventArgs.FormData;
            Guid formId = xFormData.FormId;
            Guid formDataId = (Guid)xFormData.Id;

            RedirectToYourConfirmationPage(formId, formDataId);

In the event, add formId and formDataId as query strings when redirecting to your page.

You can also in that event read the posted information by using formData.GetValue["NameOfField"] where NameOfField represents the name given to the fields in the XForm editor, or formData.GetValues() to get a list of all data.

Note that the keys are the Name, not the visitor friendly label of each field. This might not be usable for the visitor to read.

Reading posted data after redirect

After your redirect, simply use XFormData.CreateInstance to get your posted data.

            Guid formId = Guid.Parse(Request.QueryString["formId"]);
            Guid formDataId = Guid.Parse(Request.QueryString["formId"]);

            XForm xForm = XForm.CreateInstance(formId);
            SerializableXmlDocument document = xForm.document;

            XFormData xFormData = XFormData.CreateInstance(formDataId, formId);

Here you can find the XFormData with the same information as when the visitor posted the form.

In the xform.Document you should also be able to parse the XML to find the fields and their labels that could be good to display for the visitor.

Edited, Oct 31, 2015 15:40

Thanks Alf Nilsson. It was very useful to me.

Nov 19, 2015 17:24
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.