Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Extending Marketing Forms with JavaScript

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am attempting to perform some field validation on a Landing Page using some javascript that I'm working on.

Long story short, I am confused as to where I need to inject the <script> tags as the documentation is kind of all over the place, both here in the community as well as this article everyone keeps posting: https://docs.microsoft.com/en-us/dynamics365/marketing/developer/marketing-form-client-side-extensibility 

Can someone please instruct me clearly where to place the <script> tags so that they'll be called correctly when the form is submitted? Script below:

-------------

MsCrmMkt.MsCrmFormLoader.on('formSubmit'function(event) {
   
  var firstName = document.getElementById('3f746946-34b4-442c-a677-e232cdd2bc40').value;

  if (firstName.value.length >= 3) {
  alert("First Name must contain 3 or more letters");
  event.preventDefault();
});
 
--------------
Thanks in advance!
  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Extending Marketing Forms with JavaScript

    Hi DCReina,

    We shouldn't put code to source code of marketing form, because additional content will always be ignored/cleared.

    In other word, HTML of marketing form is only used to generate/render marketing form.

    Instead, please put script to source code of marketing page.

    (HTML of marketing form is part of HTML of marketing page.)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Extending Marketing Forms with JavaScript

    Hi Clofly!

    Thanks for the quick response. I just don't seen the <head><body> tags anywhere in the editor:

    pastedimage1613742656869v1.png

    I am guessing that it's because the form is being hosted as a script somewhere in a portal? This is the main source of my confusion...

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Extending Marketing Forms with JavaScript

    Hi Partner,

    You could put script function inside body tag.

    e.g:

    
    
    Landing page
    
    
    ...
    
    
    

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans