4

I created a landing page which auto-populates first name, last name and the email. Now I need to pass these 3 along with what radio buttons are selected by the user to a data extension other than the sent one.

I guess is something to do with the submit button for the radio buttons form but how? I have to tell somehow which data extension and what fields/values to add but I don't know how.

Is there any easy way to do that?

Thanks, VD

12

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)=%%"
}
  • This is really useful Jon, thanks for such a detailed answer, I will give this a try and let you know how it goes! – Snowalker Sep 22 '15 at 12:36
  • I receive an error - I checked the data extension and the field names are identical as per my script: "The Data Extension field name for a InsertData function call is invalid. A field of this name does not exist." – Snowalker Sep 22 '15 at 14:31
  • Can you post the de fields and your insert data function in a comment? – Jon Sakas Sep 22 '15 at 14:33
  • I have problems pasting the code here because of the multiple @ so I had to use jsfiddle: jsfiddle.net/gvwcej1v – Snowalker Sep 22 '15 at 15:09
  • Either remove "Date",Now() from the InsertDE function, or add a Date field called Date to your Registered DE. – Jon Sakas Sep 22 '15 at 15:17
1

when creating the AJAX request I had to use a GET rather than a POST so the "RequestParameter" would pick it up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.