web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Error Message in Marketing Form

(0) ShareShare
ReportReport
Posted on by 251

Hello everyone,

i have a Marketing form and i need to change the display error message see Picture.

my form : 2020_2D00_12_2D00_23-16_5F00_28_5F00_21_2D00_Newsletter-abonnieren-_5F00_-Digital_2D00_Kompass.png

and i want That my error message be like This:2020_2D00_12_2D00_23-16_5F00_28_5F00_59_2D00_Kontakt-_5F00_-Digital_2D00_Kompass.png

here is my Code

Test Newsletter

Abonnieren Sie unseren
Test Newsletter!

Nach der Übermittlung Ihrer Kontaktdaten erhalten Sie von info@test.de einen Bestätigungslink, um die Anmeldung abzuschließen.

* Pflichtfelder

*
*
 
 

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Hedi,

    We need to write code to achieve custom form validator, here is my sample based on your description and requirement.

    1. In source code of marketing form, add "is-required" as extra class name to input elements that you want to apply custom validator with.  

    7673.a1.JPG

    2. Add following code to source code of corresponding marketing page.(You can put it after end tag of body.)

    Test

    (I add custom validator to Last Name and Email)

    1: Leave both of fields value empty

    pastedimage1608796896791v1.png

    2 Leave Email field empty

    pastedimage1608797018335v2.png

    3. Leave Last Name empty

    pastedimage1608797055478v3.png

    Submission will success if both of required fields are filled with data.

    Reference:

    Extend marketing forms using code (Dynamics 365 Marketing Developer Guide) | Microsoft Docs

    Client-side form validation - Learn web development | MDN (mozilla.org)

    Regards,

    Clofly

  • Hedi bn Profile Picture
    251 on at

    Hi cloflyMao Thank u very much for your answer.

    i tried to do your Solution but it still not working can u give me mor Info

    I Modify my Code like this i add the class is-required j´for the Email Text.

    
        
    
    
    
    Digital-Kompass-Newsletter

    Abonnieren Sie unseren
    Digital-Kompass Newsletter!

    Nach der Übermittlung Ihrer Kontaktdaten erhalten Sie von info@digital-kompass.de einen Bestätigungslink, um die Anmeldung abzuschließen.

    * Pflichtfelder

    *
    *
     
     

     

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi hedi,

    It seems that the form tag is already placed in source code, if so, please change code inside the script tag to the following:

    const form = document.getElementsByTagName("form")[0];
    
    const errorDiv = document.createElement("div");
    errorDiv.classList.add("error-div");
    
    const closeButton = document.createElement("span");
    closeButton.setAttribute("id", "close");
    closeButton.innerText = "x";
    errorDiv.appendChild(closeButton);
    
    form.parentNode.insertBefore(errorDiv, form);
    
    document.addEventListener("click", function (e) {
        if (e.target && e.target.id == "close") {
            errorDiv.classList.remove("active");
        }
    });
    
    addEvent(form, "submit", function () {
        const requiredFields = document.getElementsByClassName("is-required");
    
        const isValid = [];
    
        for (let i = 0; i < requiredFields.length; i  ) {
            if (requiredFields[i].value === "") {
                if (requiredFields[i].parentNode.querySelector("label") !== null) {
                    var fieldName = requiredFields[i].parentNode.querySelector("label").innerText;
                    addErrorMessage(i, fieldName);
                    isValid[i] = false;
                }
            } else {
                clearErrorMessage(i);
                isValid[i] = true;
            }
        }
    
        if (isValid.every((bool) => bool) === false) {
            errorDiv.classList.add("active");
            return false;
        } else {
            errorDiv.classList.remove("active");
            // Pass validation
            return true;
        }
    })
    
    function addErrorMessage(index, name) {
        const errorMsg = document.getElementById("error-"   index);
        if (errorMsg === null) {
            errorDiv.innerHTML  = "

    " name "is required.

    "; } } function clearErrorMessage(index) { const errorMsg = document.getElementById("error-" index); if (errorMsg !== null) { errorMsg.remove(); } } function addEvent(element, event, callback) { let previousEventCallBack = element["on" event]; element["on" event] = function (e) { const output = callback(e); if (output === false) return false; if (typeof previousEventCallBack === "function") { output = previousEventCallBack(e); if (output === false) return false; } }; }

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 176

#2
ManoVerse Profile Picture

ManoVerse 149 Super User 2026 Season 1

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 57 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans