Skip to content

Instantly share code, notes, and snippets.

@PetersonDave
Last active January 7, 2017 12:57
Show Gist options
  • Save PetersonDave/5096452 to your computer and use it in GitHub Desktop.
Save PetersonDave/5096452 to your computer and use it in GitHub Desktop.
Web forms for marketers redirect assumes the success page is relative to the form item in the tree (template: /sitecore/templates/Web Forms for Marketers/Form). When this is not the case, wffm builds a redirect URL which is not valid. Since the success page is defined using a general link field, we don't have a Guid to lookup the actual success …
/*
Extends: Sitecore.Form.Core.Pipelines.FormSubmit
forms.config needs to be updated to:
<successAction>
<processor type="MyCustom.Pipelines.SuccessRedirect, MyLibrary"/>
<processor type="Sitecore.Form.Core.Pipelines.FormSubmit.FormatSuccessMessage, Sitecore.Forms.Core"/>
</successAction>
*/
public class SuccessRedirect : ClientPipelineArgs
{
public void Process(SubmitSuccessArgs args)
{
Assert.IsNotNull(args, "args");
if (args.Form == null)
{
Uri uri = null;
if (Uri.TryCreate(args.Result, UriKind.RelativeOrAbsolute, out uri))
{
bool isUriValid = uri != null && !string.IsNullOrEmpty(uri.PathAndQuery);
if (isUriValid)
{
args.AbortPipeline();
WebUtil.Redirect(args.Result, false);
}
}
}
else
{
if (args.Form.SuccessRedirect)
{
var url = GetRedirectUrl(args);
if (!string.IsNullOrEmpty(url))
{
args.AbortPipeline();
WebUtil.Redirect(url, false);
}
}
}
}
private string GetRedirectUrl(SubmitSuccessArgs args)
{
string url = string.Empty;
var path = "/sitecore/content" + args.Form.SuccessPage.Url; // don't love the hard-coded path here. Other ideas?
if (!string.IsNullOrEmpty(path))
{
var item = Sitecore.Context.Database.Items[path];
if (item != null)
{
url = LinkManager.GetItemUrl(item);
}
}
return url;
}
}
@jsabra1
Copy link

jsabra1 commented Jan 7, 2017

Hi @PetersonDave, Does this mean this is the reason for the reload of the form page that occurs on submit before actually forwarding the request to the success page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment