Check form input against existing lead data for that user

lbeecher
Level 1

Check form input against existing lead data for that user

Hi!

 

I have a page with content locked behind a login, and I need to cover a scenario where a user has signed up to access this page, but is not currently cookied as a known user. They'll be putting their email address into a form, which I'd like to compare against all leads in the database. If their email address is found in the database, I'd like to see if they are included in a specific list (which would have a yes or no value). If they are included in that list, they get access to the page content.

 

Here's the code I have currently - as you'll see, I'm having some trouble figuring out how to connect to the leads database. 

 

I need to...

1. Grab their inputted value of the email field in the form

2. Look for that email address in the leads database

3. If they're found in the database, I need to grab all of their lead info based on their email address

4. I need to check the value of a specific piece of that lead info

 

You'll see some stuff about auth codes in here - we may change that in the future, but I believe the main roadblock I'm facing currently is grabbing this info from the database.

 

Thank you so much!!

 

 

<script>
           MktoForms2.loadForm("[url]", "[instance]", 1195, function(form) {

              form.onSuccess(function(vals, originalThankYouURL) {

                 var thankYouURL = "/insider-access/" + vals.authCode;         

                 var newFollowUpURL = thankYouURL;              


                 if ( **The lead data associated with this email address has a specific piece of access marked true** ) {
                    location.href = newFollowUpURL;
                 } else {
					alert("Sorry we couldn't find your information, please sign up" );
                 }

                 return false;

               });  

             });
</script>

 

 

 

6 REPLIES 6
Max_Garrett
Level 2 - Champion

Re: Check form input against existing lead data for that user

could you make this a 2-step verification where they must click a link in an email from marketo to get to gated content?

SanfordWhiteman
Level 10 - Community Moderator

Re: Check form input against existing lead data for that user

There's one flaw in your plan: the use of a Static List. That will not be feasible. However, if you switch to a person field (Boolean to indicate membership or DateTime to indicate membership + added date) this is doable.

 

You do it using my Pre-Fill JS (search past posts for links), submitting a simple email form and polling the DTP every 100ms until it's filled with their info. We've set this up for a few preference centers.

 

If you do implement this, be aware that the person doesn't need to prove they can get email at the provided address.

lbeecher
Level 1

Re: Check form input against existing lead data for that user

Thank you! I don't believe we have a static list - we are actually looking to check if a boolean field = true, based off their email address and auth code. We don't need to verify the email address itself as being real, just need to check it against the existing data for that address to see if we can grant them access.

Taking a look at the pre-fill code now!

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Check form input against existing lead data for that user

@lbeecher, here's the link to Sandy’s prefill approach. As you have mentioned that a unknown person would need to input the email address in the form, and when they submit the form they would get the Munchkin session associated with their person record in Marketo and the DTP/DTO prefill script will only query data of the person associated with that session. The code in the onSuccess handler would only be executed when the form is submitted successfully, and you could load the data from prefill JS post that (if the prefill JS isn’t able to return data in case the Munchkin session doesn’t get immediately associated to a known person record in Marketo, then you could also follow Sandy’s approach of querying for data every 100 ms until you the prefill JS returns response.). You should ideally gate this content page behind a form with password so people can’t access data that isn’t their own. Apologies if I’m missing anything here. 

lbeecher
Level 1

Re: Check form input against existing lead data for that user

Thanks! 

 

So right now we have a form with an email and an auth code to prevent data access. I have the prefill setup, but I'm unsure how to connect this data to our form. We'd like it to let people past the gate if their account comes back as true for our boolean field, and we'd like to prompt them to sign up if not. The actual showing and hiding of the gate and the prompt are something I know how to code, but I'm lost otherwise.

 

We found this script of Sandy's and I think it can be adapted to our needs, but I'm not sure how. 

<script src="//learn.playplusgo.com/js/forms2/js/forms2.min.js"></script><form id="mktoForm_1195"></form>
         <script>
           MktoForms2.loadForm("[URL]", "[IGA #]", 1195, function(form) {
            form.onSuccess(function(vals, originalThankYouURL) {
            var thankYouURL = "/[our-url]/" + vals.selfServiceFormAuthCode,
              thankYouIframe = document.createElement("iframe"),
              totalAttempts = 1,
              delayInterval = 1000;

            thankYouIframe.src=thankYouURL;
            thankYouIframe.style.display = "none";
            thankYouIframe.addEventListener("load", function(e) {
              if (window.mktoAssociatedLead && mktoAssociatedLead.Email != vals.Email) {
                alert("Sorry we couldn't find your information, please sign up" );
                buttonEl.disabled = false;
                buttonEl.textContent = "Lookup Subscriptions";
              } else if (window.mktoAssociatedLead) {
                form.setValues({
                  Active_Subscriptions_Indicator__c : mktoAssociatedLead.memberOfLists
                });
                [emailEl,authCodeEl].forEach(function(el){
                  el.disabled = true; // disable Email and Auth Code inputs
                });        
                buttonEl.disabled = false;
                buttonEl.textContent = "Update Subscriptions";
                form.onSuccess();
              }
            });
           });
            </script>

 

lbeecher
Level 1

Re: Check form input against existing lead data for that user

Update - I think I've gotten somewhere, but I still have a ways to go. As far as I can tell, the other components of this are working, but here's where I'm stuck. 

 

When I add a console.log(mktoFields) into the cb section, I can see that the fields are in fact being pulled, but only from existing cookies. That's where I got the "if (insiderAccess === 1)". As I've mentioned, I need to check the info from a new submission of the form. I've tried putting the DTO/DTP  inside the form.onSuccess section to no avail, and unfortunately I didn't have any luck finding a reference on how to set up polling for a specific interval.

 

I'm hoping I'm close here, really appreciate any help anyone can give me!

 

MktoForms2.whenReady(function(form) {
      
    var DTO = new SimpleDTO({
    domain: "[url]",
    dataSrc: "[dataSrc]",
    debug: true,
    mode: "receive",
    cb: function(instance){
       var mktoFields = DTO.getGlobal()["mktoPreFillFields"];
       DTO.cleanup();
       form.setValuesCoerced(mktoFields);
    }
    });
    
    form.onSuccess(function(vals, originalThankYouURL) {
        
       var thankYouURL = "/insider-access/" + vals.authCode;         

       var newFollowUpURL = thankYouURL;

       var emailField = "{{lead.Email}}";
       var emailVal = vals.emailField;

       let insiderAccess = "{{lead.whitePaperAccess}}";

       if ( insiderAccess === 1 ) {
         location.href = newFollowUpURL;
       } else {
          alert("Sorry we couldn't find your information, please sign up" );
       }

       return false;

     }); 
   });