You are here:
Connect an External Form to a Form Handler
After you create and publish a form handler, configure your external form to send data to Salesforce.
Required Editions
| User Permissions Needed | |
|---|---|
| To create a form handler: | Marketing Cloud Manager permission set AND Any CMS workspace contributor role |
| To publish a form handler: | Marketing Cloud Manager permission set AND A CMS workspace contributor role of content admin or content manager |
| To configure the CORS allowlist: | Modify All Data |
Before you complete these steps, create and publish a form handler.
There are two ways to send data from your form to Salesforce. Select the connection type that best suits the structure and capabilities of your site.
| JavaScript Snippet (Client-Side) | Direct POST URL (Server-Side) |
|
|---|---|---|
| How it works | A script on your page sends form data to Salesforce when a visitor submits the form. | Your form posts data directly to a Salesforce URL, with no script on the page. |
| Add to your site | A <script> tag and form attributes that you paste into the HTML
for your page. |
A URL that you set as the action for your form or webhook destination. |
| Best suited for | Pages where you control the HTML and can add scripts. | Third-party form builders that don’t allow custom scripts, pages with strict Content Security Policy (CSP) rules, and forms that post from a backend server. |
| Supports web tracking | Yes | No |
| Supports identity resolution | Yes | No |
| Requires a CORS Allowlist entry | Yes | Yes |
Both methods send data to the same form handler and trigger the same flow. Both methods also require you to authorize your domain in the CORS Allowlist.
With either type of connection, make sure each field in your form uses an HTML
name attribute that exactly matches the corresponding external field name in
the form handler. If the names don’t match, the form handler doesn’t capture the value. For
example, if you mapped the external field name email_address to the
Email field, the name attribute for the corresponding field
in the form must also be email_address.
Option 1: Configure Your Form to Use a Client-Side Connection
Use this method when you control the HTML for your page and can add a script to it. Because the script runs in the visitor’s browser, this method supports web tracking and identity resolution. As a result, this method can connect a form submission to a visitor’s web activity.
- Publish the form handler.
-
On the Code Snippet tab, under Client-Side Form Handler, copy the tracking script. The
script resembles this example.
<script async src="https://YOUR_DOMAIN/lp/assets/scripts/external-form-handler-host.min.js" onload="SFDCFormHandler.init('https://YOUR_DOMAIN/lp')"></script> -
In the HTML code for the site, paste the script before the closing
</body>tag. -
On the Code Snippet tab, copy the form attributes. The attributes resemble this
example.
<form id="CONTENT_KEY" data-uma-forms="true"></form> -
In your HTML, add the
idanddata-uma-formsattributes to the<form>tag. -
Confirm that the HTML
nameattribute for each form field matches the mapped external field name. - Add the domain that hosts your form to the CORS Allowlist. This step authorizes your domain to send submissions to Salesforce.
- To monitor user engagement, turn on web tracking.
When a visitor submits the form, the script sends the data to Salesforce, and the form handler processes the submission and triggers your flow. The form handler then redirects them to the success or error URL that you configured.
Option 2: Configure Your Form to Use a Server-Side Connection
Use a server-side connection when you aren’t able to add code to your page or make custom configurations to your code. With this method, the form handler gives you a destination URL, and you configure the form to send its data to that URL. Because you don’t embed a script, this method works with form tools that don’t allow custom JavaScript. This method is also useful with pages that have strict Content Security Policy (CSP) rules, and with forms that submit from a backend server.
-
On the Code Snippet tab for the form handler, under Server-Side Form Handler, copy the
form action URL. The URL resembles this example.
https://YOUR_DOMAIN/lp/cms/form/submit/v1/CONTENT_KEY -
Configure the form to send the data to Salesforce. The implementation steps depend on how
you implement your form.
If you use a third-party form builder or plugin In the settings for the third-party tool, find the field for configuring the form’s action, post-to URL, or webhook destination. Enter the Salesforce URL in that field. If you can modify the HTML but can’t add a script Set the actionattribute of your<form>tag to the Salesforce URL, and set themethodattribute toPOST.If your form uses a backend process Send a POST request to the Salesforce URL with the form data, with application/x-www-form-urlencodedencoding. -
Confirm that the name of each field matches the mapped external field name exactly.
The form handler captures fields only when they match exactly.
- Add the domain that hosts your form to the CORS Allowlist. This step authorizes your domain to send submissions to Salesforce.
Configure the CORS Allowlist
Both connection methods require you to authorize your domain before Salesforce accepts form submissions. If you don’t authorize your domain, then Salesforce blocks the submission before it’s processed. To authorize your domain, add it to the CORS Allowlist.
-
Identify the domain that hosts the form, such as
https://www.example.com. To authorize all subdomains, use a wildcard, such ashttps://*.example.com. - Add the domain to the CORS allowlist.
Test the Form
After you connect your form to the form handler, test it to make sure that it behaves the way you expect it to.
- On the form, submit a test entry and confirm that you’re sent to the success URL.
-
In Salesforce, check to see if a record corresponding to the test entry was created or
updated.
Tip If a record isn’t created or updated after submitting a test entry, confirm that each form field’s name attribute matches an external field name. If the form handler is connected to a flow, confirm that the flow completes without errors.
