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; | |
} | |
} |
Yes -- if the rootPath attribute on your site node has a value different than /sitecore/content, then using Sitecore.Context.Site.RootPath won't work.
How about putting it in a patch include configuration file instead?
That's a good idea. I like it!
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
@scjunkie I previously tried the code above, but got a path which was invalid. This is due to a specific configuration in a multi-site setup:
WFFM Form Page: sitecore/content/my-site/home/form
WFFM Form Success Page: sitecore/content/my-site/home/form/success
WFFM Form: /sitecore/content/my-site/forms/my-form
For the configuration above, the values map to:
Sitecore.Context.Site.RootPath: sitecore/content/my-site
args.Form.SuccessPage.Url: /my-site/home/form/success
Keep in mind this issue is specific to my configuration. While I get an invalid URL, others who have a different configuration will not get an invalid URL. The impact may be a URL, which works, but has the site home node in its URL.