1

As we all know if we want to create a Custom Preference Center we need to use Cloud Pages HTML type page insert the HTML and AMPScript to UPSERT/update data. I have the AMP Script in place for my 3 questions, though I dont have a submit button, please share what code I need for a on click, on submit page, what am I missing here.

%%[
var @emailaddr,@mkt,@sub
set @emailaddr = AttributeValue("emailaddr")
set @mkt = AttributeValue("MarketingOptIn")
set @sub = AttributeValue("_SubscriberKey")
]%%
<div><label for="EmailAddress">EmailAddress *</label></div>
<div><input type="email" value="%%=v(@emailaddr)=%%" name="EmailAddress" data-field-type="EmailAddress" data-validation="email" required="required" data-validation-message="Please enter an email address."></div>
<div><label for="SubscriberKey">SubscriberKey *</label></div>
<div><input type="text" value="%%=v(@sub)=%%" name="SubscriberKey" data-field-type="Text" required="required" data-validation-message="Please fill out this field."></div>
<div><label for="MarketingOptIn">MarketingOptIn</label></div>
<div><input type="text" value="%%=v(@mkt)=%%" name="MarketingOptIn" data-field-type="Text"></div>

1 Answer 1

2

I will recommend following approach, using RequestParameter()

%%[ IF RequestParameter("action") == "save" THEN
SET @email = RequestParameter("EmailAddress")
SET @optin = RequestParameter("MarketingOptIn")
SET @sub = RequestParameter("SubscriberKey")
UpsertDE('Profile',1,'SubscriberKey',@sub,'email',@email,'optin',@optin)
]%%

You have now been updated

%%[ 
ELSE
var @emailaddr,@mkt,@sub
set @emailaddr = AttributeValue("emailaddr")
set @mkt = AttributeValue("MarketingOptIn")
set @sub = AttributeValue("_SubscriberKey")
]%%

<div><label for="EmailAddress">EmailAddress *</label></div>
<div><input type="email" value="%%=v(@emailaddr)=%%" name="EmailAddress" data-field-type="EmailAddress" data-validation="email" required="required" data-validation-message="Please enter an email address."></div>
<div><label for="SubscriberKey">SubscriberKey *</label></div>
<div><input type="text" value="%%=v(@sub)=%%" name="SubscriberKey" data-field-type="Text" required="required" data-validation-message="Please fill out this field."></div>
<div><label for="MarketingOptIn">MarketingOptIn</label></div>
<div><input type="text" value="%%=v(@mkt)=%%" name="MarketingOptIn" data-field-type="Text"></div>

%%[ ENDIF ]%%

You set the action to include the ?action=save parameter, so the right AmpScript snippet gets executed

4
  • Lucus, what is the command for the "on submit" button. Currently my page does not a submit button.
    – Driven996
    Commented Dec 14, 2017 at 15:55
  • Well - you need to have a submit button, with an action defined for your form. Otherwise, you will not be able to send the field values: developer.mozilla.org/en-US/docs/Learn/HTML/Forms/… Commented Dec 14, 2017 at 17:50
  • Hi @Driven996 - remember to mark answers as accepted. I can see this is missing on all the questions you've asked. Commented Dec 18, 2017 at 9:06
  • I am going to attempt it today and if I does, I sure will. Thank you.
    – Driven996
    Commented Dec 18, 2017 at 18:58

You must log in to answer this question.

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