Amey Holden

View Original

Prevent submission of a non-business email address in Dynamics 365 Marketing forms

Dynamics 365 Marketing Landing Page forms are general-purpose form for collecting contact information. They can be hosted on a Power Apps portal or on your own external website that submits values back to Dynamics 365 Marketing.

Many B2B (business to business) companies do not want to receive ‘Contact Us’ information from people who do not have a business email address. This magic little snippet of JavaScript code will prevent a marketing form from being submitted if the email provided is under the domain Yahoo!, Gmail or Hotmail. Obviously there are many others which could be added here, but now you have the snippet of code you can update it to fit your requirements as needed.

This post focuses on a Portal Landing Page hosted form but the same code can be applied to an externally hosted Dynamics 365 Marketing form, using the method explained here.

Create a form

Create the Landing Page form as you usually would for a marketing form, its the same process to begin whether its embedded or hosted on a Marketing Page. Make sure you add a field for ‘Business Email’.

Find the form field ID

First we need to find the ID of the ‘Business Email’ marketing field we want to apply the rules to. Select the HTML tab of the marketing form. Search for the field name (ctrl+f). The ID will be within the <input></input> tags inside the id=”” copy that onto your notepad, this is _YOUR_FIELD_ID_ e.g. 2d77477c-744a-ec14-8c60-22224811c1a2

Embed the form on a Marketing Page

Create a ‘Landing Page’ Marketing Page and embed the Marketing Form you just created.

Add the magical JavaScript snippet

See this content in the original post

Copy the above snippet, then replace the _YOUR_FIELD_ID_ with the relevant value from above. Drop it in just below the first closed </script> tag that loads the marketing JS library.

Prevent non-business email addresses on form submit

Try out your form submissions both with and without a business email address - magic!

Handy Link for developer brains ->
Further JavaScript for embedded form extensibility options documentation -> https://docs.microsoft.com/en-us/dynamics365/marketing/developer/marketing-form-client-side-extensibility