If Known User Show Form - Conditional | Community
Skip to main content
Amelia_Thompson
Level 2
November 2, 2019
Solved

If Known User Show Form - Conditional

  • November 2, 2019
  • 2 replies
  • 4280 views

Hello - So basically I am trying to use the 'If Known Visitor, Show: Custom HTML' form feature. What I am trying to do is show the form if the first name for a known user meets certain conditions. 

If the known user's:

//  First name contains punctuation marks OR

// First name is 'update'  OR
// First name has only one letter in it
then --> show the form
Otherwise if they are a known user and their first name doesn't meet any of those conditions, hide the form. 
Is this possible to do this based on those conditions?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

You'd put this CSS stylesheet* in your <head>:

<style>
.mktoForm
{
position: absolute;
visibility: hidden;
}
.mktoForm[data-dynamic-displayable="true"] {
position: static;
visibility: visible;
}
</style> ‍‍‍‍‍‍‍‍‍‍

Then this JS right before the closing </body> tag:

<script>
(function(){
var mktoFields = {
FirstName : "{{Lead.First Name}}"
}

if( mktoFields.FirstName == "Amelia" ){
MktoForms2.whenReady(function(form){
var formEl = form.getFormElem()[0];
formEl.setAttribute("data-dynamic-displayable",true);
});
}
})();‍‍‍‍‍‍‍‍‍‍‍‍
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Substituting your actual conditions for == "Amelia".

I need to note that your notion of "punctuation marks" isn't specific enough. There are lots of marks (Unicode Punctuation, * character categories) that are found in First Names. In Latin-1 alone, periods, parentheses, hyphens, apostrophes, and quotation marks are part of given names as entered on forms. Sure, there are hundreds of other punctuation marks that are not typically part of given names, but you have to ask yourself whether it's worth the penalty of telling people Your name is not your name in order to catch a few outliers. We err on the side of trust; I'm not going to tell someone who enters "Jane #2" that they can't buy a product, while some spam lead who happens to use the first name "Joe" is good. .

Also note that South Indian given names (assigned initials) frequently are only one letter.  It would be wrong to tell someone their effective first name is not "S", because that is their name, and it's not supposed to be spelled out. You'd just be alienating millions of potential leads.

* If anybody is curious about why I didn't use display:none; it's because the forms library must calculate the rendered width accurately.

Do this whenever you want to show a form conditionally (as opposed to load a form conditionally).

Here the named mktoForm element is always loading; otherwise you'd have to switch to  the embed, which is wrong on Marketo LPs.

2 replies

SanfordWhiteman
Level 10
November 2, 2019

Not out-of-the-box but certainly with a some helper JS.  Is this on a Marketo LP?

Amelia_Thompson
Level 2
November 2, 2019

Yes, the form is on a Marketo Landing Page. Do you know what helper JS should be used?

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
November 2, 2019

You'd put this CSS stylesheet* in your <head>:

<style>
.mktoForm
{
position: absolute;
visibility: hidden;
}
.mktoForm[data-dynamic-displayable="true"] {
position: static;
visibility: visible;
}
</style> ‍‍‍‍‍‍‍‍‍‍

Then this JS right before the closing </body> tag:

<script>
(function(){
var mktoFields = {
FirstName : "{{Lead.First Name}}"
}

if( mktoFields.FirstName == "Amelia" ){
MktoForms2.whenReady(function(form){
var formEl = form.getFormElem()[0];
formEl.setAttribute("data-dynamic-displayable",true);
});
}
})();‍‍‍‍‍‍‍‍‍‍‍‍
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Substituting your actual conditions for == "Amelia".

I need to note that your notion of "punctuation marks" isn't specific enough. There are lots of marks (Unicode Punctuation, * character categories) that are found in First Names. In Latin-1 alone, periods, parentheses, hyphens, apostrophes, and quotation marks are part of given names as entered on forms. Sure, there are hundreds of other punctuation marks that are not typically part of given names, but you have to ask yourself whether it's worth the penalty of telling people Your name is not your name in order to catch a few outliers. We err on the side of trust; I'm not going to tell someone who enters "Jane #2" that they can't buy a product, while some spam lead who happens to use the first name "Joe" is good. .

Also note that South Indian given names (assigned initials) frequently are only one letter.  It would be wrong to tell someone their effective first name is not "S", because that is their name, and it's not supposed to be spelled out. You'd just be alienating millions of potential leads.

* If anybody is curious about why I didn't use display:none; it's because the forms library must calculate the rendered width accurately.

Do this whenever you want to show a form conditionally (as opposed to load a form conditionally).

Here the named mktoForm element is always loading; otherwise you'd have to switch to  the embed, which is wrong on Marketo LPs.

SanfordWhiteman
Level 10
November 5, 2019

@OP please return to your thread and check replies.

Amelia_Thompson
Level 2
November 5, 2019

Sorry, thank you I've marked your answer as correct.