Create a Sales Cloud-integrated lead capture form using AMPscript

SmartCapture forms provide a quick, user-friendly way to create simple forms and use them in Salesforce Marketing Cloud journeys, but they are not very versatile and often can create more problems than they actually solve.

In this tutorial, you will learn how to create a form using HTML and AMPscript and include functions that will let you quickly push the collected data into your instance of Sales/Service Cloud.

Create an HTML form

First, let’s create a very simple HTML form. If you’ve never created forms in HTML, you can start with reading this short overview on w3schools. The form action method attribute specifies how to send form-data. In this case, we are using post, which appends form-data inside the body of the HTTP request (data is not shown is in URL).

The RequestParameter('PAGEURL') function reloads the page when the form is submitted, posting the form parameters back to the same page, which are then retrieved by the RequestParameter() AMPscript functions. The form has a hidden submitted field. If this value is present, which it would be after submitting the form, it will trigger the evaluation of the AMPscript functions. Let’s add them to the form now.

Create form logic using AMPscript

Let’s start simple with creating a Sales Cloud Lead using the data collected in the form. The AMPscript needs to be placed at the top, as it should be evaluated upon form submission and prevent the form fields from being displayed after it’s been submitted. In the below script, we use the CreateSalesforceObject function to create a new Lead:

We can extend the logic a bit by checking first if the Lead with the given email address already exists in Sales Cloud, and if yes – updating their data, or if not – creating a new Lead:

Let’s now add the Lead to a Campaign in Sales Cloud. You will need to hardcode the Campaign Id into the script. Note that you cannot add the same Lead to a campaign twice, so if the Lead has already been added to the campaign, you will get an error. Let’s add creating a new Campaign Member to the script:

And now, let’s put the icing on the cake and send a confirmation email to the Lead. You will need to create a Triggered Send beforehand – if you’re not sure how, read my blog post: Send a triggered email using AMPscript. We will hardcode the Triggered Send external key as @ts_extkey, pass the Lead ID and Email Address to a new Subscriber object and invoke creation of a new Triggered Send object:

You now have a fully functional lead capture form integrated with Sales Cloud!

If you’d like to see this in action, fill in this example form that I created to receive a confirmation email:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s