0

I'm trying to embed a form in a micro site that seems all responses back to a data extension. I can use separate content areas and make one area a smart capture because of the layout of the page.

Using this question as a guide, I created a second page in the micro site with the content type JSON and the code below. Still, when I submit the form, I am taken to the JSON handler page and no data is populated in the data extension.

How can I use the two pages (the page itself and the handler) to send responses back to the data extension?

Form HTML:

form class="container well col-sm-5" method="post" action='http://pages.email.alm.com/page.aspx?QS=5c591a8916642e73a1574a390f28d9ec1cac7f5638a2380cfa761b0588edcf50'>

      <div class="form-group" >

        <label for="name">Name</label>
        <input type="text" class="form-control" id="Name" placeholder="Your name" value=" ">

      </div>

      <div class="form-group">

        <label for="email">Email</label>
        <input type="email" class="form-control" id="email" placeholder="Your email" value=" ">

      </div>

      <div class="form-group">

        <label for="nomineesname">Nominee's Name</label>
        <input type="text" class="form-control" id="nomineesname" placeholder="Nominee's name" value="">

      </div>

      <div class="form-group">

        <label for="nomineesemail">Nominee's Email</label>
        <input type="email" class="form-control" id="nomineesemail" placeholder="Nominee's email" value="">

      </div> etc. etc. ...

Script on Handler Page:

VAR @de, @de_col, @de_statusCode, @de_statusMsg, @errorCode

SET @de = CreateObject("DataExtensionObject")
SetObjectProperty(@de, "CustomerKey", "FA6623CC-C3A1-492C-AA7A-D4D47E7CD902")


IF NOT IsNull(RequestParameter("Name")) THEN
    SET @de_col = CreateObject("APIProperty")
    SetObjectProperty(@de_col, "Name", "Name")
    SetObjectProperty(@de_col, "Value", RequestParameter("Name"))
    AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF

IF NOT IsNull(RequestParameter("Email")) THEN
    SET @de_col = CreateObject("APIProperty")
    SetObjectProperty(@de_col, "Name", "Email")
    SetObjectProperty(@de_col, "Value", RequestParameter("Email"))
    AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF

IF NOT IsNull(RequestParameter("Nomineesname")) THEN
    SET @de_col = CreateObject("APIProperty")
    SetObjectProperty(@de_col, "Name", "Nomineesname")
    SetObjectProperty(@de_col, "Value", RequestParameter("Nomineesname"))
    AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF

IF NOT IsNull(RequestParameter("Nomineesemail")) THEN
    SET @de_col = CreateObject("APIProperty")
    SetObjectProperty(@de_col, "Name", "Nomineesemail")
    SetObjectProperty(@de_col, "Value", RequestParameter("Nomineesemail"))
    AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF

IF NOT IsNull(RequestParameter("Description")) THEN
    SET @de_col = CreateObject("APIProperty")
    SetObjectProperty(@de_col, "Name", "Description")
    SetObjectProperty(@de_col, "Value", RequestParameter("Description"))
    AddObjectArrayItem(@de, "Properties", @de_col)
ENDIF


SET @de_statusCode = InvokeCreate(@de, @de_statusMsg, @errorCode)

IF @de_statusCode != "OK" THEN
    RaiseError(@de_statusMsg, 0, @de_statusCode, @errorCode)
ENDIF

1 Answer 1

2

I generally do this with a single page. Here's a boilerplate that I created, which utilizes SSJS and a little bit of AMPScript:

<script type="text/javascript" runat="server">

    Platform.Load("core", "1.1.1");

    var debug = false;
    var request = {};
    SetVar("urlThis", Platform.Request.RequestURL);

    if (Request.Method == "GET") {

        if (debug) {
            Write("GET<br/>");
        }

        // retrieve values from the subscriber context or URL parameters using Attribute.GetValue("VARNAME") or Request.GetQueryStringParameter("VARNAME");

        // in your email, use the AMPScript MicrositeURL() function with the landing page page id to ensure the subscriber context is passed to your landing page

        // set AMPScript variables using the SetVar function below


    } else if (Request.Method == "POST") {

        if (debug) {
            Write("POST<br/>");
        }

        // retrieve POST values using Request.GetFormField("VARNAME")

        // do the appropriate API call

        // redirect to the RESULTURL based on success or failure of API call

        Redirect(RESULTURL,false);
    }


    function SetVar(varName, varValue){
        request[varName] = varValue;
        Variable.SetValue(varName, varValue);
    }

    function isEmpty(str) {
      return (!str || 0 === str.length);
    }
    if (debug) {
        Write("<br><br>debug output: " + Stringify(request));
    }


</script><!DOCTYPE HTML>
<html>
    <head></head>
    <body>
      <form id="formName" action="%%=v(@urlThis)=%%" method="post" enctype="application/x-www-form-urlencoded">
        default form values with %%=v(@VARNAME)=%% or <ctrl:eval>VARNAME</ctrl:eval>
      </form>
    </body>
</html>
2
  • thanks for the reply. Maybe you could walk me through this a little more? I'm not too well versed in SSJS. I tried to create a layout with two content boxes side by side putting a smart capture in one and text in the other. But the text/copy pushed itself across 90% of the page and makes the form unusable. Have you ever seen that before? Jun 17, 2016 at 23:04
  • I try not to not use Smart Capture. Jun 24, 2016 at 17:38

You must log in to answer this question.

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