• About this blog
  • About me
  • Contact
Sitecore XperiencesThe things I've seen as a Sitecore Professional
  • About this blog
  • About me
  • Contact
Menu
  • About this blog
  • About me
  • Contact
  • (Bug-free) Custom Form IDs in Sitecore Forms

    July 6, 2020 Rodrigo Peplau 0

    Some time ago I was challenged by one requirement need from the marketing team, related to the Sitecore Forms that we put together for them.

    In order to do a better event tracking with Google Tag Manager, we had to give the power for Content Editor to customize the form ID. Instead of a hard to read string, composed by concatenations of the form and the session Guids, we should enable any kind of arbitrary string to be configured.

    Speaking to my long time friend and Hackathon partner Joao Neto, who is great with Experience Forms, he put together this solution. What amazing friend hu? Joao’s solution does the trick as the marketing team requested, but introduced a 500 error that was affecting the Google ranking – and that, as we know, is also something that marketers love to hate.

    So I was provided with the time necessary to investigate and fix this error and now share it with our community.

    The error

    The forms with custom IDs will trigger 500 errors when doing the field tracking – which happens when you fill a field and move to the next field by pressing TAB.

    These errors are not visible to final users, they occur behind the scenes and can potentially affect your search ranking. You can see them happening by using tools like Fiddler or Developer Tools.

    The errors are also tracked as Error Interactions of your current Contact:

    Error 500 on Sitecore Forms

    Why it breaks?

    The issue happens because there are some native Javascript that uses the Form ID to extract the Session Id. Since we have modified the Form ID, then this code will fail, causing the issue.

    The fix

    In order to fix this issue, we will store the original form ID as another attribute in the form, then change the defective javascript to take from that attribute instead of the Form ID itself.

     

    STEP 1 – Save the original ID

    Looking back to Joao’s code, the class that we need to modify is “SetFormId“.

    Modify the line 34 adding the following two lines, before assigning the customId to the form:

    if (!args.Attributes.ContainsKey("originalId"))
       args.Attributes.Add("originalId",args.FormHtmlId);
    // Setup custom form ID
    args.FormHtmlId = customId;
    

     

    STEP 2 – Change the JS file to pick from that attribute

    The following native JS must be changed: /sitecore%20modules/Web/ExperienceForms/scripts/form.tracking.js

    The method “getSessionId” must be modified to the following code:

    function getSessionId(form) {
       var formId = form[0].id;
       // The fix starts here
       if ($jq(form[0]).attr("originalId")!==undefined)
          formId = $jq(form[0]).attr("originalId");
       // The fix ends here
       var targetId = formId.slice(0, -(formId.length - formId.lastIndexOf("_") - 1)) + "FormSessionId";
       var element = form.find("input[type='hidden'][id=\"" + targetId + "\"]");
       return element.val();
    }
    
    

    Categories: Experience Forms

    Malformed querystring breaks Sitecore Experience Forms (Value cannot be null. Parameter name: key) Sitecore 10.1 Form Send E-mail VS Community Send E-mail

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

Proudly 10x Sitecore MVP!
(2016-2025)

Localization

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award

Recent Comments

  • navan on Meet MVPinny: the AI-Powered Sitecore Assistant
  • Adriana on Content generation with Sitecore Connect and ChatGPT
  • NAVAN on Automatic Sitecore NuGet upgrades with Powershell
  • Hedipo S Menezes on Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing
  • Rodrigo Peplau on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.

Archives

  • March 2025
  • January 2025
  • June 2024
  • April 2024
  • February 2024
  • December 2023
  • November 2023
  • August 2023
  • July 2023
  • January 2023
  • February 2022
  • December 2021
  • November 2021
  • March 2021
  • July 2020
  • February 2020
  • September 2019
  • July 2019
  • April 2019
  • March 2019
  • December 2018
  • February 2018
  • January 2018
  • November 2017
  • September 2017
  • August 2017
  • July 2017
  • March 2017
  • February 2017
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • April 2016
  • November 2015
  • September 2015
  • July 2015
  • April 2015
  • March 2015
  • February 2015

Categories

  • Actions
  • Active Directory
  • Analytics
  • Architecture
  • Bug fixing
  • CDP/Personalize
  • ChatGPT
  • Content Edition Experience
  • Content Hub
  • Continuous Integration
  • Dev
  • Development
  • Environments
  • Experience Editor
  • Experience Forms
  • Front-end
  • Hackathon
  • Health Check builds
  • Helix
  • How To
  • LDAP
  • MVP
  • MVP Summit
  • MVPinny
  • Phantom JS
  • Powershell
  • QA
  • Richtext Editor
  • Rules
  • Security Provider
  • SIF
  • Sitecore 9
  • Sitecore API
  • Sitecore Community
  • SItecore Connect
  • Sitecore Modules
  • Sitecore Rocks
  • Sitecore Rule Processor
  • Sitecore Symposium
  • SPE
  • SPE-only Alliance
  • SPEAK
  • SUG
  • Support Ticket
  • TDS
  • Team City
  • Uncategorized
  • Upgrades
  • Visual Studio
  • WFFM
  • Workflow
  • XConnect
  • xDB
  • XM Cloud

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award
  • Error enabling GraphQL IDE with XM Cloud
  • Meet MVPinny: the AI-Powered Sitecore Assistant
  • Content generation with Sitecore Connect and ChatGPT
  • XM Cloud Starter Kit with Content Hub Integration
  • Meet the (Brand new) Advanced Powershell Packaging Features

Tag Cloud

    Architecture Automation Continuous Integration Debugging Development Environments Hackathon How To PhantomJS Powershell Server Roles TDS Team City Team Development for Sitecore XConnect

Pages

  • About this blog
  • About me
  • Contact

Search

Copyright © 2015 Rodrigo Peplau Theme created by PWT. Powered by WordPress.org