Last active
January 7, 2017 12:57
-
-
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 …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?