Website field validation requires http | Community
Skip to main content
Level 2
Nov 20, 2020 4:52 PM UTC
Solved

Website field validation requires http

Hello,

 

On our most used form, we require the person to enter their company website. As the website field is a URL field, it is requiring the user to enter the http protocol in the website they are entering. I would suspect that this rigorous requirement is dropping our form fills.

 

Is there a way to not require the http protocol before the web address? I know forms 2.0 does have some additional validation techniques, but I have not kicked the tires on it yet.

 

Thanks,

Kyle

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Nov 20, 2020 7:06 PM UTC

The better way is to parse their email domain...

Marketo actually populates Website from the Email Address domain by default. Problem is, that's not guaranteed to be accurate. A lead can use their personal email address to sign up for a trial, but would be OK w/providing the actual company domain on the form (think enterprise web software, etc.).

6 replies

SanfordWhiteman
Level 10
Nov 20, 2020 7:16 PM UTC

Posted this code the other day in response to an almost identical question (unfortunately, the forum search feature is really bad so I can't even find that thread now!).

 

This code will do naive validation of a String field as being domain-name-like, with at least a 2-part name. It also allows but doesn't require http:// or https://:

 

/* * @author Sanford Whiteman * @version v1.0.6 2020-11-11 * @copyright © 2020 Sanford Whiteman * @license Hippocratic 2.1: This license must appear with all reproductions of this software. * */ MktoForms2.whenReady(function(mktoForm){ const formEl = mktoForm.getFormElem()[0]; mktoForm.onValidate(function(nativeValid){ const hostnameFields = ["Website"], hostnameMsg = "Must be a valid domain/subdomain name"; /* NO NEED TO TOUCH BELOW THIS LINE */ if (!nativeValid) return; let currentValues = mktoForm.getValues(), originalSubmittable = mktoForm.submittable(), firstOffender; const RE_DOMAIN_NAIVE = /^(https?:\/\/)?(?:[a-z0-9][a-z0-9-]{0,61}[a-z0-9]?)(?:\.[a-z0-9][a-z0-9-]{0,61}[a-z0-9]?)*(?:\.[a-z0-9][a-z0-9-]{0,61}[a-z0-9])$/i; hostnameFields.some(function(fieldName){ if( !RE_DOMAIN_NAIVE.test(currentValues[fieldName]) ){ firstOffender = formEl.querySelector("[name='"+ fieldName + "']"); return false; } }); if(firstOffender){ mktoForm.submittable(false); mktoForm.showErrorMessage(hostnameMsg,MktoForms2.$(firstOffender)); } else { mktoForm.submittable(originalSubmittable); } }); });

 

Translate
Josh_Hill13
Level 10
Nov 20, 2020 6:14 PM UTC

Use a string or text field and clean it up later using JS or in SFDC.


Depends how badly you want "https" in there.

Translate
Josh_Hill13
Level 10
Nov 20, 2020 6:15 PM UTC

The better way is to parse their email domain and/or use an enrichment service later on in Marketo/SFDC. Why ask someone for their domain ?

Translate
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Nov 20, 2020 7:06 PM UTC

The better way is to parse their email domain...

Marketo actually populates Website from the Email Address domain by default. Problem is, that's not guaranteed to be accurate. A lead can use their personal email address to sign up for a trial, but would be OK w/providing the actual company domain on the form (think enterprise web software, etc.).

Translate