0

I created an HTML form and sent an email with that form.

When the recipient fills the form and submits it, then the data should be added to the targeted Data Extension.

Here is my code:

 <html lang="en">
  <head>
  </head>

  <body>

%%[
var @email, @firstName, @lastName, @createSfRecord, @createDeRecord

set @firstName = RequestParameter('firstName')
set @lastName = RequestParameter('lastName')
set @email = RequestParameter('email')

if RequestParameter("submitted") == "submitted" then

   set @createSfRecord = CreateSalesforceObject(
    'Account', 3,
    'FirstName', @firstName,
    'LastName', @lastName,
    'Email', @email)

   set @createDeRecord = InsertDE(
    'Abhi_DE1',
    'First Name',@firstName,
    'Last Name',@lastName,
    'Email',@email)
endif

]%%

<form action="%%=RequestParameter('%%profile_center_url%%')=%%" method="post">
<label>First Name</label>
<input type="text" name="firstName">

<label>Last Name</label>
<input type="text" name="lastName">

<label>Email</label>
<input type="text" name="email">

<input id="submitted" type="hidden" name="submitted" value="submitted" />

<input type="submit" value="Submit">
</form>

%%=IIF(RequestParameter("submitted") == "submitted", '<p>Your form has been submitted.</p>','')=%%

</body>
</html><table cellpadding="2" cellspacing="0" width="600" ID="Table5" Border=0><tr><td><font face="verdana" size="1" color="#444444">This email was sent by: <b>%%Member_Busname%%</b><br>%%Member_Addr%% %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br><br></font></td></tr></table><a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>
1
  • <form action="%%=RequestParameter('%%profile_center_url%%')=%%" method="post"> i think action attribute is wrong, did you try using only %%profile_center_url%% in the action? try this and let me know.
    – Abhishek
    Commented Nov 21, 2018 at 12:33

1 Answer 1

2

I am confused on a lot of your post and I think there are a few fundamentals that you are missing on this.

  1. Did you say you put this form inside of an email? If so, realize that a good many email clients won't let HTML forms work inside of them and that all your AMPscript about processing the results is useless as the submit=submitted will only happen once the form is POSTed and you cannot POST to an email. Meaning that you will need to post to a custom built Cloudpage or to the DEmanager via Web Collect.
  2. You have your 'action' for your HTML form posting to the profile center. Why? The profile center will not have the capabilities to do what you wanted upon POST. Plus your users will be confused why they are brought to the profile center after filling in a form. It is kinda like opening a door to find another door behind that door.
  3. RequestParameter() is used only on webpages to gather parameters from the GET/POST data passed. To get attributes or DE fields, you would use the personalization string method (e.g. %%firstname%%) or use (my preference) the AttributeValue() function (e.g. SET @fname = AttributeValue('firstname')).

So, lets say this form is instead on a page, you should:

  • Realize that %%profile_center_url%% along with most personalization strings are not usually passed to SFMC Cloudpages or Landing pages unless you use the CloudPagesURL() function
  • That in order for you AMPScript to work, you need the page to post to itself (and it has to be a Cloudpage/Landing Page).
  • Your %%=RequestParameter('%%profile_center_url%%')=%% is just wrong. You would either need to manual pass this url via a var and use %%=RequestParameter('yourParametername')=%% or if you passed via CloudPagesURL() or it is inside an email then you can use %%profile_center_url%% or %%=AttributeValue('profile_center_url')=%%.

You must log in to answer this question.

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