0

I have created an Interactive Form email, in which I have added Fallback content as Freeform block.

Fallback content has a button, from where I'm passing the values in emailaddr & _subscriberkey.

href="%%=RedirectTo(CloudPagesURL(xxx, 'Email', emailaddr, 'SubscriberKey', _subscriberkey))=%%"code to

-Cloud page code contains the code to retrieve the values using Requestparameter function. I have added my code below. When I click on the button it takes me to Cloudpage. However, when I click on submit button I get 500 internal server error.

%%[

set @subscriberkey = _subscriberKey
set @Email = emailaddr

if RequestParameter("submitted") == true then

set @Q1  = RequestParameter("Q1")
set @Q2  = RequestParameter("Q2")
Set @Q3  = RequestParameter("Q3")

  InsertData('MyDE','Email',@Email, 'Q1', @Q1, 'Q2', @Q2, 'Q3', @Q3, 'SubscriberKey',@subscriberkey, 'AddedDate',Now())
endif
]%%

      %%[ if RequestParameter("submitted") == true then ]%%
         <p align="center" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 18px; color: #fffff; padding:0px 0px 10px 0px;"><b>Thank you.</b></p>
    %%[ else ]%%  

<h1 align="center" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; color: #fffff; padding:0px 0px 10px 0px;">We Value your feedback.</h1>
  <form action="http://cloud.xxx.xxxx.com/xxx" method="post" id="MyForm" align="center" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; color: #fffff; padding:0px 0px 15px 0px;">
  <p align="left" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; color: #fffff; padding:0px 0px 10px 0px;">  <label class="checkbox-inline">
      <input type="checkbox" id="Q1" name="Q1" value="True">1. abcdefg
    </label> <br>
    <label class="checkbox-inline">
      <input type="checkbox" id="Q2" name="Q2" value="True">2. hijklm
    </label><br>
    <label class="checkbox-inline">
      <input type="checkbox" id="Q3" name="Q3" value="True">3. nopqrst
    </label>
   <br></p>

    
  </form>
<p align="center" style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; color: #fffff; padding:0px 0px 10px 0px;">
<button type="submit" form="MyForm" name="submitted" value="true">SUBMIT</button></p>
%%[ endif ]%%

I Need help to understand if I'm missing something here.

1
  • When you submit/post the email and subkey don't get carried across which is likely causing the insert to toss an error. Try adding those two values as hidden inputs Commented May 15, 2021 at 23:43

1 Answer 1

2

In relation to the narrow question, "How to retrieve parameters from a URL?", you can get the value of your "emailaddr" query string parameter using the QueryParameter() or RequestParameter() functions. Given in your example this code runs for GETS and POSTS, stick with RequestParameter():

SET @subscriberkey = RequestParameter('SubscriberKey')

You can then persist this value in your form post using a hidden field:

<input type="hidden" id="SubscriberKey" name="SubscriberKey" value="%%=v(@subscriberKey)=%%">

However, there's no need to add SubKey and Email Address to the query string behind your button in the fallback content or explicitly as hidden fields in your form. When using CloudPageURL(), SFMC adds the qs query string to the URL the user clicks on from the email. This provides "context" to the CloudPage being visited. The page knows various details about the subscriber visiting the page including Email Address and SubscriberKey, as well as about the email the subscriber's clicking from, like JobID, ListID, BatchID etc. So, the href on your button should simply be:

<a alias="My Form" href="%%=RedirectTo(CloudPagesURL(xxx))=%%">Click Me</a>

Note: If you're using Web Analytics Parameters, you may need to add an "&" into the above to signal to WAC that there is already a query string in your URL... RedirectTo(Concat(CloudPagesURL(xxx),'&'))=%%

In your form in your CloudPage, firstly remove the value for the form's action. This'll ensure the page just submits to itself - a page whose URL contains the context and hence has access regular AMScript personalization strings.

<form action="" method="post" id="MyForm" align="center">

Secondly, if "MyDE" has a primary key on SubscriberKey, use UpsertData() to avoid primary key violations when the script runs to insert into the table and use regular AMPScript personalization strings for your Email and SubscriberKey values:

/* InsertData */
InsertData('MyDE','Email',emailaddr,'Q1,@Q1,'Q2',@Q2,'Q3',@Q3, 'SubscriberKey',_SubscriberKey,'AddedDate',Now())

/* UpsertData based on SubscriberKey */
UpsertData('MyDE',1,'SubscriberKey',_SubscriberKey,'Email',emailaddr,'Q1,@Q1,'Q2',@Q2,'Q3',@Q3)

You must log in to answer this question.

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