Try our conversational search powered by Generative AI!

XForms only works for master language branch.

Vote:
 

Hello everone! 

I have a problem that I need help with. We have a XForms block on a multiple language site. It is possible to create a Xform and then use it on different language pages. The problem is that the form will redirect to the master language page, instead of the current language page pointed out in the XForm. So if we have an order form on the Swedish site, the Xforms will redirect to the "thank you"-page of the master language instead of the Swedish thank you-page. And if I try to add a form on the Swedish site only, it is not possible to post. I get redirected to an 500 error page. I can add the form to the page, but can not post.

This is the code that are responsible for redirecting to the "Thank you"-page: 

[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult XFormPost(XFormPostedData xFormpostedData)
{
    var formdata = new XFormPageHelper().GetXFormData(this, xFormpostedData);
    if (XFormActionHelper.DoAction(formdata, xFormpostedData, true))
   {
        var guid = xFormpostedData.XForm.PageGuidAfterPost;
        if (!guid.Equals(System.Guid.Empty))
       {
            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var pageThankYou = contentRepository.Get<PageData>(guid);
            var urlBuilder = new UrlBuilder(pageThankYou.LinkURL);
            Global.UrlRewriteProvider.ConvertToExternal(urlBuilder, pageThankYou.PageLink, System.Text.UTF8Encoding.UTF8);
            Response.Redirect(urlBuilder.ToString());
       }
   }
   return RedirectToAction("Index");
}



Any help you can give me in this matter are warmly appreciated. I am new to XForms, so dont worry about being to be to detailed! I appreciate it! :=) 

Thanks! Have a great summer! 

Friendly greetings from Mattias! 

#73051
Jul 04, 2013 15:57
Vote:
 

Can you post the error you get when it's directed to the 500 error page?

#73071
Jul 05, 2013 5:38
Vote:
 

I have following workaround for the issue. It will fix the action url with javascript. Just add following snippet for the page. 

<script>
    (function ($) {
        // FIX Episerver xforms handling
        $(window).ready(function () {
            var $xform = $('.form.xform');
            if ($xform.length === 0) {
                return;
            }

            var action = $xform.attr('action');
            var segments = action.split('?', 2);
            var path = segments[0]; // path is invalid
            var query = segments[1];

            var currentPath = window.location.pathname; // use real path instead
            
            path = (currentPath.indexOf("XFormPost/") !== -1) ? currentPath : currentPath + 'XFormPost/';
            action = path + '?' + query;
            $xform.attr('action', action);
        });
    })(jQuery);
</script>

    

Fixing the url on the server side is a lot harder due to how episerver handles xforms property rendering. Therefore javascript was a quick and easy way to workaround the issue until it gets fixed by episerver.

Btw. asp.net mvc helpers Html.BeginForm and Url.Action are also flawed the same way; they too use the master language url instead of the language branch url. But these two can be fixed by setting the language manually. e.g. using own helper methods:

    public static MvcForm EpiBeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName)
    {
        var currentCulture = ContentLanguage.PreferredCulture;
        var languageBranch = currentCulture.Name;
        return htmlHelper.BeginForm(actionName, controllerName, new { Language = languageBranch }, FormMethod.Post);
    }
    
    public static string EpiAction(this UrlHelper urlHelper, string actionName, string controllerName)
    {
        var currentCulture = ContentLanguage.PreferredCulture;
        var languageBranch = currentCulture.Name;
        return urlHelper.Action(actionName, controllerName, new { Language = languageBranch });
    }

     

 

 

 

#73200
Edited, Jul 10, 2013 10:13
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.