I have a W2C form that need to change the ContactName text field to lookup field that will contain all the contacts in our CRM org and I try to using AMPScript to do it. However, I want to know is that possible to embedded AMPScript into W2C ?
Keeping in mind that pre-polutating forms from emails always comes with the risk of someone forwarding their email and someone else seeing their data - this can be done, relatively simply. Assuming you send your email from Marketing Cloud.
You need the function CloudPagesURL() to send encrypted data to your form page. The link in your email that leads to the form will look like this:
<a href="%%=RedirectTo(CloudPagesURL(____))=%%">click me</a>
fill in the CloudPageId of your Cloudpage in the empty space. This will create an encrypted link pointing to your page with encrypted information about the Subscriber the email went to etc. You'll see the parameter "qs" at the end of the link, something like ?qs=iwasdhasfhasfhafhafhuqztqqtw
Make sure your user HAS a subscriberkey, i.e. is on All Subscribers List already, then this will work in the email preview. Otherwise, you need to make a real sendout before you can test.
When accessed through such a link, your Cloudpage now has access to the personalization strings like _subscriberkey and emailaddr that it received in the qs parameter. It automatically decrypts them.
More about personalization strings:
You now have two options:
A) make a Lookup on the cloudpage leveraging the _subscriberkey or emailaddr that the page received to find the relevant information about the relevant in a data extension inside marketing cloud:
Assuming you have a DE called nameOfDataExtension and you want the value of the field Lastname, and the SubscriberKey is in the Field "Subscriberkey":
%%[Set @lastname = Lookup("nameOfDataExtension","Lastname","SubscriberKey",_subscriberKey)]%%
You could theoretically do this directly in Sales Cloud (retrieveSalesforceObjects() function), but I would always go with data extensions if possible.
B) If the value of "lastname" is already in your sendout data extension, you can also directly add its value as additional parameter to the CloudpagesURL() functio, which adds it to the encrypted information in qs parameter. Then use that instead of writing a lookup:
Assuming "lastName" is the field which holds the lastname in your sendout data extension, this could be your link in the email:
<a href="%%=RedirectTo(CloudPagesURL(____,"lastname",[lastName]))=%%">click me</a>
It will ONLY work when either previewed against a user with a subscriberkey and using a data extension that has a field "lastname", or when sent to a data extension with this field.
In any case, on your Cloudpage you can now display the value of @lastname in your form input field using:
<input type="text" value="%%=v(@lastname)=%%">
see also: https://ampscript.guide/cloudpagesurl/