3

My website has been built in multi languages. I am building forms using Sitecore Form as well. However, I'm facing an issue with Redirect to Page action under submit actions.

I noticed that when I'm in Chinese language, submit form then it redirects to a Thank you page but this page is in English version instead of Chinese.

May anyone help to advise on this? I'm using Sitecore 9.0 update 1.

enter image description here

2
  • Does your Thank you page have a version in Chinese language? Do you maybe have Item Fallback configured for the Thank you page? Is Language Embedding always required for the site where you put the form? Commented Jun 27, 2019 at 14:25
  • @ArtsemPrashkovich Yes, I have Thank you page in Chinese language. It requires language embedding as well. I'm using SXA version 1.6 and use Virtual Folder "/zh" for Chinese (e.g zh-HK).
    – Jonathan
    Commented Jun 27, 2019 at 15:52

1 Answer 1

5

We encountered this same issue - the reason was that when Sitecore creates the AJAX URL for submitting the form data, it does not include a language parameter. So when the form submission is being processed, the context language of the request is not necessarily the language of the page being viewed.

We fixed this by altering the form.renderForm pipeline to override the InitializeAjaxOptions step to add this parameter. As it's a standard context parameter, it gets picked up by the request and changes the context accordingly.

public class LanguageAwareInitializeAjaxOptions : InitializeAjaxOptions
{   
    private const string languageKey = "sc_lang";

    public LanguageAwareInitializeAjaxOptions(IFormRenderingContext formRenderingContext) 
        : base(formRenderingContext)
    {
    }

    public override void Process(RenderFormEventArgs args)
    {
        if (!args.IsPost && !args.QueryString.ContainsKey(languageKey))
        {
            args.QueryString.Add(languageKey, Sitecore.Context.Language.Name);
        }

        base.Process(args);
    }
}

You then just need to patch this replacement pipeline in:

<forms.renderForm>
    <processor patch:instead="*[@type='Sitecore.ExperienceForms.Mvc.Pipelines.RenderForm.InitializeAjaxOptions, Sitecore.ExperienceForms.Mvc']"
               type="Your.Solution.Pipelines.RenderForm.LanguageAwareInitializeAjaxOptions, Your.Solution" resolve="true"/>
  </forms.renderForm>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.