0

i have created a simple html survey form under cloudpages which constains several questions with radio buttons and some with text boxes for answers. I want to know how to get radio button's values selected by user along with text in textboxes to a data extension.

Is it something which can be done through SSJS or AMpscript? I was trying to use this script in html form

    <script runat ="server" language = "javascript">
platform.Load("core", "1")

var requestDE = DataExtnsion.Init("EED34E60-1B36-41E7-B7F8-21428023921C");
requestDE.Rows.Add({
        some code

    });
</script>

This is the page for Survey

I would also like to know how to capture the email address of subscriber who filled the survey as I haven't included any email address field in this form.

Updated ampscript

 <html>
<head>
    <style type="text/css">
        body {
            margin: 50px;
            color: #555;
            font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Verdana, sans-serif;
        }
    </style>
%%[
var @q5_overallHow5, @q6_didOur6, @q8_wouldYou8, @q10_whatAspect10, @q11_whatAspect, @q12_pleaseExplain, @q15_additionalComments15

set @q5_overallHow5 = RequestParameter('q5_overallHow5')
set @q6_didOur6 = RequestParameter('q6_didOur6')
set @q8_wouldYou8 = RequestParameter('q8_wouldYou8')
set @q10_whatAspect10 = RequestParameter('q10_whatAspect10')
set @q11_whatAspect = RequestParameter('q11_whatAspect')
set @q12_pleaseExplain = RequestParameter('q12_pleaseExplain')
set @q15_additionalComments15 = RequestParameter('q15_additionalComments15')

InsertData("SurveyResults",
           "q5_overallHow5",@q5_overallHow5,
           "q6_didOur6",@q6_didOur6,
           "q8_wouldYou8", @q8_wouldYou8, 
           "q10_whatAspect10", @q10_whatAspect10, 
           "q11_whatAspect", @q11_whatAspect, 
           "q12_pleaseExplain" @q12_pleaseExplain, 
           "q15_additionalComments15", @q15_additionalComments15
          )
]%%


</head>
<body>
    <h2>Thank you</h2>
    <p>Thank you for completing the survey.</p>
</body>
</html>
0

1 Answer 1

3

There are a few different approaches to achieve this that I've used before, including:

  • AJAX request to a code resource
  • posting form to itself
  • posting form to a thank you page

For simplicity and given your level of experience with AMPscript, I'd recommend you post the form to a thank you page, which I see that are already doing.

I've setup a thank you page which takes the first two fields from your form and inserts them to a Data Extension, which you can review here.

Firstly, create a DE to contain your form fields. I've created a DE named "SurveyResults" with fields that match your form field names, e.g. q5_overallHow5, q6_didOur6, etc. Make sure these fields in your DE are nullable (as you do not appear to have any required form fields on your form).

Next, update the example that I have provided, to declare and set the variables for each form field (which I've named the same as the form field names, for simplicity), then add these name and variable pairs to the InsertData function in my sample code:

%%[
var @q5_overallHow5, @q6_didOur6

set @q5_overallHow5 = RequestParameter('q5_overallHow5')
set @q6_didOur6 = RequestParameter('q6_didOur6')

InsertData("SurveyResults",
           "q5_overallHow5",@q5_overallHow5,
           "q6_didOur6",@q6_didOur6
          )
]%%

When the form is submitted, the thank you page retrieves the form parameters and uses the InsertData() AMPscript function to insert the values into the DE.

Update

Pragyanshu added an additional question (in a comment to my answer) related to capturing the subscribers' email address on the form. This is easily achieved thanks to the CloudPagesURL() function. I've provided the additional steps below.

1. Email Link

Firstly, in your email use the CloudPagesURL() function to define the link to the survey CloudPage:

%%[
var @survey
Set @survey = CloudPagesURL(925)
]%%

<a href="%%=RedirectTo(@survey)=%%">view survey</a>

Where 925 is the ID of your CloudPage. You can retrieve the ID of the CloudPage from the page properties panel:

This will link to the published CloudPage URL and also includes an encrypted parameter referencing the subscriber key and email address of the Subscriber who is receiving the email (really handy!)

2. Survey page

Next, add a hidden form field anywhere within the form area on your survey page (after the opening form tag and before the closing </form> tag) which looks like this:

<input type="hidden" name="email" value="%%emailaddr%%">

The Subscriber email address will be populated in this field based on the encrypted URL parameter.

3. Data Extension

Add a new email address field to your survey Data Extension named email (if it doesn't already exist)

4. Update the AMPscript block on the survey page:

%%[
var @q5_overallHow5, @q6_didOur6, @email

set @q5_overallHow5 = RequestParameter('q5_overallHow5')
set @q6_didOur6 = RequestParameter('q6_didOur6')
set @email = RequestParameter('email')

InsertData("SurveyResults",
           "q5_overallHow5",@q5_overallHow5,
           "q6_didOur6",@q6_didOur6,
           "email",@email
          )
]%%
3
  • Thank you making my life easier Eliot, just one more question I want to know how to capture their email address. who submitted the survey. Commented Apr 3, 2017 at 8:22
  • That's a great question. I've updated my answer to explain how to do this. Commented Apr 3, 2017 at 10:28
  • Thanks a ton Eliot, you explained like a boss!! Thanks again. I would also like to know if there are some good resources to learn ampscript from basic other than the salesforce dev site. Commented Apr 3, 2017 at 11:46

Not the answer you're looking for? Browse other questions tagged .