Search code examples
savesitecoreweb-forms-for-marketers

Post Data to next Page in Custom Save Action Web Form For Marketer Sitecore 8


After saving data in WFFM Custom save Action,I want to redirect Success Page with some large amount of data I am trying below line of code .

I Can use Cookies ,session or Query String and Response.Redirect(baseUrl)but i want to Cookies ,session or Query String .

 class SaveAction : WffmSaveAction
    {
        public override void Execute(ID formId, AdaptedResultList adaptedFields, ActionCallContext actionCallContext, params object[] data)
        {
             //Save Data in Service ,, Redirect to success page with below code with some data like ID

                string baseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority +
HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/success-page";

                HttpContext.Current.Response.Clear();        //
                StringBuilder sb = new StringBuilder();
                sb.Append("<html>");
                sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
                sb.AppendFormat("<form name='form' action='{0}' method='post'>", baseUrl);
                sb.AppendFormat("<input type='hidden' name='id' value='{0}'>", "123456");
                // Other params go here
                sb.Append("</form>");
                sb.Append("</body>");
                sb.Append("</html>");

                HttpContext.Current.Response.Write(sb.ToString());
                HttpContext.Current.Response.End();
                // HttpContext.Current.Response.Redirect(baseUrl);

            }
}

Above code reload the same page with no body in Html.

Am i missing something in given code ?


Solution

  • The answer might depend on whether you have an mvc form or not. In case of mvc forms, you might want to read this: http://ggullentops.blogspot.be/2016/07/sitecore-wffm-act-on-success.html. It describes hooking into the success pipeline <wffm.success> and passing data towards the success page (how exactly - querystring, session, .. is up to you(r code)). Fairly easy once you know the correct pipeline.

    There is also a great post here describing what you are trying to do - i.e. saving the data for later use in the saveaction. It's too much code to copy here but it comes down to saving the data (in session) during the save action and creating a rendering (to read and handle the data again) that you will place on the success page.

    Creating a rendering to place on your success page is something you will have to do anyway.. Don't try to redirect yourself, Sitecore does that for you.