SOLVED

Re: Website field validation requires http

Go to solution
kylej762
Level 1

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

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Website field validation requires http


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.).

View solution in original post

6 REPLIES 6
Josh_Hill13
Level 10 - Champion Alumni

Re: Website field validation requires http

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


Depends how badly you want "https" in there.

Josh_Hill13
Level 10 - Champion Alumni

Re: Website field validation requires http

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 ?

SanfordWhiteman
Level 10 - Community Moderator

Re: Website field validation requires http


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.).

kylej762
Level 1

Re: Website field validation requires http

Thanks Sanford. Tested and this is the case, but to your point does have a drawback that we would be willing to live with.

kylej762
Level 1

Re: Website field validation requires http

Thanks Josh. I agree with this sentiment but deleted it from my original post.

SanfordWhiteman
Level 10 - Community Moderator

Re: Website field validation requires http

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);
      }
   });
});