0

Would someone mind helping me add comments to a webform that was created by a 3rd party I no longer have access to and comments would really help me work my way around updating/adding to my form. IE comments that tells me which part of the code is pulling from the form and which is posting in Salesforce ("FirstName"). I'd also like to know if it's possible to have the AMPSCRIPT pre-populate any fields that we might already have from the subscriber.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {margin: 0px;
padding: 0px;
font-family:Arial, Helvetica, sans-serif;

}

form.form {

margin: 0 !important;
padding: 0 !important;
font-family:Arial, Helvetica, sans-serif !important;
}

form.form p label {

width:auto !important;
text-align: left !important;

}

form.form p {

 margin: 3px 0 !important;
     padding: 3px 0 !important;

}

form.form p span.description {
margin-left: 0px !important;
}

form.form p.no-label, form.form p.email-pref {

margin: 0 !important; 
padding: 0 !important;
}

form.form p label.inline {
line-height: 1.6em !important;
font-size:11px;   
display: block !important;

}

form.form input.text {

width:100% !important;
padding: 0px;
    box-sizing: border-box; 
}

input[type="text"], input[type="tel"], input[type="email"] {
width: 100%;
box-sizing: border-box;
}

form.form p.submit {

margin: 5px 0px 5px 3px !important;
    padding: 0;
}

form.form p.submit input {
margin: 0px 10px 10px 0px !important;
padding: 2px 12px;
}

input[type="checkbox"] {
margin: 0px 5px 0px 0px;
float: left;
display: block;
}

select{background:#fff;}

input[type=submit] {
border: dashed 1px #fff;
outline: solid 3px #E01200;
background: #E01200;
color: #fff !important;
padding: 2px 12px;
text-transform: uppercase;
font-size: 1.2em;
margin: 25px 0px;
-webkit-appearance:button;
}

input[type="submit"]:hover{
border: dashed 1px #fff !important;
outline: solid 3px #bd1203 !important;
background:#bd1203 !important;
color:#fff !important;
}

td {
line-height: 1.6em;
font-size: 12px;
}

</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.5/iframeResizer.contentWindow.min.js"></script>  
</head>
<body>

%%[ 

set @post = QueryParameter("p")
set @Email = QueryParameter("emailaddress")
set @FirstName = QueryParameter("firstname")
set @LastName = QueryParameter("lastname")
set @Phone = QueryParameter("phone")
set @Email_Opt_in = QueryParameter("Email_Opt_in")
set @SubmitDate = QueryParameter("SubmitDate")

If @post == "y" then 

    set @web = RetrieveSalesforceObjects("Lead", "Id", "Email", "=", @email)         

    if RowCount(@web) == 0 then
       CreateSalesforceObject("Lead", 5, "FirstName", @FirstName ,"LastName", @LastName, "Email",@Email,"Status","Open", "Phone", @Phone)
    else 
        row Set @row = ROW(@web,1)
        Set @Id = FIELD(@row,"Id")
        UpdateSingleSalesforceObject("Lead",@id,"FirstName", @FirstName, "LastName", @LastName, "Phone", @Phone) 
    endif 

    UpsertData("BookTour_Form", 1, "Email", @Email, "FirstName", @FirstName, "LastName", @LastName, "SubmitDate", @SubmitDate) 

    var @emailaddr,@attr, @ts, @tsDef, @ts_subkey, @ts_sub, @ts_statusCode, @errorCode
    SET @ts = CreateObject("TriggeredSend")
    SET @tsDef = CreateObject("TriggeredSendDefinition")
    SetObjectProperty(@tsDef, "CustomerKey", "Additional_Tour_Info_Trigger")
    SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

    SET @ts_sub = CreateObject("Subscriber")
    SetObjectProperty(@ts_sub, "EmailAddress", @Email)   
    SetObjectProperty(@ts_sub, "SubscriberKey", @Email)   

    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "FirstName")
    SetObjectProperty(@attr, "Value", @FirstName)
    AddObjectArrayItem(@ts_sub, "Attributes", @attr)

    SET @attr = CreateObject("Attribute")
    SetObjectProperty(@attr, "Name", "LastName")
    SetObjectProperty(@attr, "Value", @LastName)
    AddObjectArrayItem(@ts_sub, "Attributes", @attr)

    AddObjectArrayItem(@ts, "Subscribers", @ts_sub)
    SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

EndIf 
]%%

%%[

If @post == "y" then

redirect("http://www.durhamcollege.ca/book-campus-tour")

Else

]%%

<form action="http://pub.info-durhamcollege.ca/Booktour" method="POST" target='_parent'>
<input type="hidden" id="p" name="p" value="y">
<input type="hidden" id="rid" name="rid" value = "%%=v(@Id)=%%" />
<input type="hidden" id="SubmitDate" name="SubmitDate" value="%%=Now()=%%">
<table>
  <tr>
    <td>First Name
    </td>
    <tr>
      <td>
      <input  type="text" id="firstname" name="firstname" />
    </td>
    </tr>
  <tr>
    <td>Last Name*
    </td>
    </tr>
  <tr>
    <td>
    <input type="text" id="lastname" name = "lastname" required />
    </td>
      </tr>
  <tr>
    <td>Email*
    </td>
     <tr>
      <td>
        <input type="email" id="emailaddress" name = "emailaddress" required/>
    </td>
    </tr>
  <tr>
    <td>Mobile Phone*
    </td>
     <tr>
      <td>
        <input type="tel" id="phone" name = "phone" required/>
    </td>
    </tr>
    <tr>
    <td>
   <input type="checkbox" name="Email_Opt_in" value="true" required/>* Durham College values the opportunity to provide you with information. Please click here to allow us to continue to contact you via email. </td> </tr>
     <tr><td> <input type="submit" value="Submit" /></td></tr>

</table>

</form>

%%[ endif ]%%
</body>
</html>
2
  • What's your assessment of the code? Dec 13, 2016 at 14:02
  • My Assessment: Set Post for what you want to Upsert to SF. Then check if if the email already exist. if it does update if it doesn't new. My issues is I'm not sure what exactly does each part. I have a good guess but in my experience so far with HTML that's not good enough. You can spend more time fixing a little mistake if you don't know what your doing. Dec 13, 2016 at 14:23

1 Answer 1

0

As far as I understand the 'user' fills the fields in this page and press the 'Submit' button, it post the fields with hidden field 'p'= "y".

Then this page executes (field @post which comes from the 'p' parameter equal to "y") the following code, (I added the comments):

    /*Search for a LEAD with a given email*/
       set @web = RetrieveSalesforceObjects("Lead", "Id", "Email", "=", @email)    

    if RowCount(@web) == 0 then
           /*Email not found in LEAD, INSERT NEW*/
           CreateSalesforceObject("Lead", 5, "FirstName", @FirstName ,"LastName", @LastName, "Email",@Email,"Status","Open", "Phone", @Phone)
    else 
        /*Email found in LEAD, UPDATE using Id*/
        row Set @row = ROW(@web,1)
        Set @Id = FIELD(@row,"Id")
        UpdateSingleSalesforceObject("Lead",@id,"FirstName", @FirstName, "LastName", @LastName, "Phone", @Phone) 
    endif 

The code where you get the phone:

set @post = QueryParameter("p")
set @Email = QueryParameter("emailaddress")
set @FirstName = QueryParameter("firstname")
set @LastName = QueryParameter("lastname")
set @Phone = QueryParameter("phone")
set @Email_Opt_in = QueryParameter("Email_Opt_in")
set @SubmitDate = QueryParameter("SubmitDate")

If you only want to change the phone-> mobile just change it in the createSalesforceObject/UpdateSingleSalesforceObject (Phone -> Mobile)

9
  • That helps a lot. So if I want to add a new field. Let's say Country. I would add a set and that set "@Country", holds the value from the form either by the ID or Name, not sure which one. A little thrown off by the Line for UpsertData. As it does not have the "phone" string in the UpsertData , yet it actually does update based on the if/else statement. wITH var @emailaddr MY guess is this is what sends the subscriber an email after they hit submit. Dec 13, 2016 at 17:03
  • Te rest of the code, upserts the data of the DataExtension "BookTour_Form" (UpsertData("BookTour_Form",...), after that, it sends the email with Subscriber Key / External Key "Additional_Tour_Info_Trigger" with the function "InvokeCreate(..."
    – SebOB
    Dec 13, 2016 at 17:12
  • Our Lead object has Phone and Mobile. Just tried to switch anything that said phone to Mobile which did not work. If the Fields Object the "Field Label= Mobile" and the "Field Name = MobilePhone". How can I get this to work. at the moment there's not error message it appears to process but Mobile is empty Dec 13, 2016 at 19:59
  • Robert, you have to learn HTML and AMPscript. Nevertheless, this is the code where you get the phone:
    – SebOB
    Dec 14, 2016 at 8:42
  • Sorry, I updated the post with my explanation
    – SebOB
    Dec 14, 2016 at 8:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.