WFFM WebFroms Customizing the SuccessRedirect Pipeline

Like any other pipelines in Sitecore, WFFM pipelines are also customizable. I am showing you here how to customize the WFFM WebForms SuccessRedirect pipeline.

The SuccessRedirect pipeline is used to process the Success page URL which you provide on the form under the success action. This pipeline is responsible to process the URL provided by the user and can process internal, external and media URLs.

You can find SuccessRedirect class under the Sitecore.Form.Core.Pipelines.FormSubmit namespace

in the below example, I am going to add a QueryString to the success page URL. I’ll read a cookie and use its value for QueryString.

See the example here

namespace SitecoreTricks.Helper.Pipelines
{
   public class SuccessRedirect:ClientPipelineArgs
   {
     public void Process(SubmitSuccessArgs args)
     {
       Assert.IsNotNull((object)args, "args");
       if (args.Form != null)
       {
         if (!args.Form.SuccessRedirect)
              return;
         args.AbortPipeline();
         LinkField successPage = args.Form.SuccessPage;
         UrlString urlString = (UrlString)null;
         if (successPage.LinkType == "external")
             urlString = new UrlString(successPage.Url);
         else if (successPage.TargetItem != null)
         {
            switch (successPage.LinkType)
            {
               case "internal":
                    UrlOptions defaultUrlOptions = LinkManager.GetDefaultUrlOptions();
                    defaultUrlOptions.SiteResolving = Settings.Rendering.SiteResolving;
                    urlString = new UrlString(LinkManager.GetItemUrl(successPage.TargetItem, defaultUrlOptions));
                    break;
              case "media":
                   urlString = new UrlString(MediaManager.GetMediaUrl(new MediaItem(successPage.TargetItem)));
                   break;
            }
        }
        else
           DependenciesManager.Logger.Warn(string.Format("Web Forms for Marketers : Success page for the form does not exist. Form ID: '{0}'.", (object)args.Form.ID), new object());

        if (urlString == null)
            return;
        string attribute = successPage.GetAttribute("querystring");
        if (!string.IsNullOrEmpty(attribute))
             urlString.Parameters.Add(WebUtil.ParseUrlParameters(attribute));
        HttpCookie cookie = HttpContext.Current.Request.Cookies["testCookie"];
        if (cookie != null)
        {
           var finalUrl = urlString + "?" + cookie.Value;
           cookie.Expires = DateTime.Now.AddDays(-1);
           WebUtil.Redirect(finalUrl, false);
        }
        else
        {
           WebUtil.Redirect(urlString.ToString(), false);
        }
        WebUtil.Redirect(urlString.ToString(), false);
     }
     else
     {
       Uri result;
       if (!Uri.TryCreate(args.Result, UriKind.RelativeOrAbsolute, out result))
           return;
       try
       {
          string pathAndQuery = result.PathAndQuery;
       }
       catch (Exception ex)
       {
         return;
       }
       args.AbortPipeline();
       WebUtil.Redirect(args.Result, false);
     }
   }
 }
}

Once you are done with the code customizations then you need to make a config change. You need to find the Sitecore.Forms.Config file and navigate to <successAction> tag under the pipelines. Paste your custom processor there.

See the below example

<processor type=”SitecoreTricks.Helper.Pipelines.SuccessRedirect, SitecoreTricks.Helper”/>

and that’s it. you are done with your WFFM pipeline customization.