You need to set up a microsite page that handles the form submission and does something with the values. AMPscript has a function RequestParameter()
that gets values from an HTTP Post. You take these values and insert them into your DE.
A Really Simple Example
Here is the simplest example I can think of to do what you need. You will have 2 microsite pages: Form, which contains the actual HTML form, and Handle Form which handles the HTTP Post and inserts the values into your DE.
Form
<html>
<form id="myForm" method="post" action="/url/to/handle/form">
<input type="hidden" name="firstname" value="Jon" />
<input type="radio" name="beer" value="lager" />Lager<br />
<input type="radio" name="beer" value="ipa" />IPA
<input type="submit" />
</form>
</html>
Note: you need to replace the form's action
attribute with the URL to your Handle Form page
Handle Form
%%[
set @beer = RequestParameter("beer")
set @firstname = RequestParameter("firstname")
InsertData("Some Data Extension","beer",@beer,"firstname",@firstname,"Date",Now())
]%%
%%=v(@beer)=%%
<br />
%%=v(@firstname)=%%
The above example will work, but it's not great because it does not contain any validation and requires the user to navigate back if there is an issue. ExactTarget has some documentation on validating forms which can be read here: Using AMPscript to Validate Fields in a Landing Page
A More Advanced Example
This example might be beyond the scope of your question but I want to share it as it might help someone down the road. As someone who's done this more than few times in SFMC I prefer to use ajax to submit and handle the form. The Handle Form page is requested using JavaScript and has a content type of application/json
. You would select JavaScript Object Notation (JSON) from the Content Type dropdown when creating your page.
The content of your Handle Form page would look something like the code below. It looks for the required values and if they are present it inserts into the DE and returns success as true. Otherwise it returns false allowing you to handle the error appropriately on the front end. Using JavaScript to handle the form in this way will allow you to to provide a better user experience for whoever is using your site.
%%[
set @success = true
set @beer = RequestParameter("beer")
set @firstname = RequestParameter("firstname")
if Empty(@beer) or Empty(@firstname) then
set @success = false
else
InsertData("Some Data Extension","beer",@beer,"firstname",@firstname,"Date",Now())
endif
]%%
{
"success" : "%%=v(@success)=%%"
}
Best Answer
Typically, there are two ways to go about this, and they're both reasonably sufficient. AMPScript's web services API can be leveraged to update the data extensions, and so can server-side Javascript and their custom Javascript platform functions.
If you are to go the route of using AMPScript then your form page will also contain the processing code. Since AMPScript runs at page load time the page will need to pass information along in the form post and your ampscript can run the processing functions to update the Data Extension when the form data is present. You'll need to build a web service API object using AMPscript and then insert or update that object with a command.
The other way to go about it is to asynchronously post the data to a separate server-side javascript page and send the response back to the form page for confirmation. You can load js libraries on cloud pages / microsites so you should be able to leverage frameworks like jquery. Your form page then listens for the response and updates appropriately when the success response is passed.
There's plenty of documentation on these methods out there, and here's some initial links to get your wheels turning:
SSJS: https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-programmatic-content.meta/mc-programmatic-content/ssjs_serverSideJavaScript.htm
Ampscript Functions: https://developer.salesforce.com/docs/atlas.en-us.mc-programmatic-content.meta/mc-programmatic-content/functions.htm