[SalesForce] Using AMPScript to Pre-Populate a Smart Capture Forms in Salesforce Marketing Cloud

I'm trying to send an email to Data Extension A that will link users to a Marketing Cloud Landing Page with a Smart Capture form. The Smart Capture form is updating Data Extension B.

The form that updates Data Extension B has a field for email address, and I'm trying to pre-populate that field on the Smart Capture form with the email address in the sending data extension, Data Extension A.

I'm having trouble getting it to work. Does anyone have some sample AMPScript that I could try for this?

Thanks.

Best Answer

There are 2 ways that we use to pass user information to Landing Pages:

Option 1: QueryParameter

In Email:

%%[VAR @email,@name,@landingpage
Set @email = 'email@example.com' 
Set @name = 'Test' 
Set @landingpage = Concat('https://pub.exacttarget.com/landingpage?email=',@email,'&name=',@name)
]%% 
<a href = "%%=RedirectTo(@landingpage)=%%">Click Here</a>

On LandingPage:

<form>
  Name:<br>
  <input type="text" name="name" value="%%=v(QueryParameter('name'))=%%"><br>
  Email:<br>
  <input type="text" name="email" value="%%=v(QueryParameter('email'))=%%">
</form>


Option 2: LookupRows & DataView

In Email:

%%[VAR @subscriberkey,@landingpage
Set @subscriberkey= '123456789' 
Set @landingpage = Concat('https://pub.exacttarget.com/landingpage?key=',@subscriberkey)
]%% 
<a href = "%%=RedirectTo(@landingpage)=%%">Click Here</a>

On LandingPage:

%%[
var @key, @email, @name
set @key = QueryParameter("key")
set @email = FIELD(ROW(LookupRows("_Subscribers","SubscriberKey",@key),1), "EmailAddress")
set @name = FIELD(ROW(LookupRows("Example_Customer_Data_DE","SubscriberKey",@key),1), "Name")
]%%
<form>
  Name:<br>
  <input type="text" name="name" value="%%=v(@name)=%%"><br>
  Email:<br>
  <input type="text" name="email" value="%%=v(@email)=%%">
</form>


Note that both of these methods are taking values from AMPScript at the time of send, and appending them to the destination URL string. For this reason, you may need some security/hashing/encoding to prevent malicious attempts to access your customer data via the form.

I hope that helps.