", "answerCount": 1, "upvoteCount": 0, "datePublished": "2022-08-28T01:32:54.000Z", "author": { "@type": "Person", "name": "Brandon Rollins", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EW8pVQAT", "affiliation": { "@type": "Organization", "name": "Varsity Brands" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hello,   Have you tried this without the validation?   It would be good to rule out if this works without your custom validation to identify that as the issue. ", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000JdBsESAV", "datePublished": "2022-08-29T18:15:19.000Z", "author": { "@type": "Person", "name": "Tom Bassett", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000EKVyvQAH", "affiliation": { "@type": "Organization", "name": "Vera Solutions" } } } ] } }
Skip to main content

I am updating a custom web to lead form but adding a validation error message. The error message will display and have the user to either enter an email or phone number. I was able to add this but the prior error and validation does not seem to be working, specifically the one to check if the email is formatted correctly. I can however enter the email or phone on the form, and continue to submit the form, but the lead is not coming into Salesforce. I am guessing this is because i messed up the validation somewhere. I am posting to code and any help is greatly appreciated, I have been working on this issue for far to long. 

 

function ValidateForm() {             var email = document.getElementById("email").value;             if(document.getElementById("first_name").value.length == 0) {                 helperMsg += "Please enter First Name \n\r";             }             if(document.getElementById("last_name").value.length == 0) {                 helperMsg += "Please enter Last Name \n\r";             }             if((document.getElementById("zip").value.length != 5) && (document.getElementById("country").value == "United States")) {                 helperMsg += "Please enter 5 digit Zip/Postal Code number \n\r";             }             if(document.getElementById("dateInput").value.length == 0) {                 helperMsg += "Please enter your Date of Birth \n\r";             }             if(document.getElementById("dateInput").value.length != 0) {                 checkAge();             }             if(document.getElementById("00Nt0000000H0l1").value.length != 0) {                 checkHt();             }             if(document.getElementById("servedInMilitary").value.length === 0) {                 helperMsg += "Please indicate if you have Prior Military Service \n\r";             }             if(getPriors === "y" && (document.getElementById("branchOfService").value.length === 0 || document.getElementById("00Nt0000000H0ld").value.length === 0)) {                 helperMsg += "Prior Service applicants please provide Branch of Service and Prior Rate info \n\r";             }             if(grecaptcha.getResponse().length == 0) {                 helperMsg += "Please verify that you are not a robot \n\r";             }             if((document.getElementById("email").value.length ==0 ) && (document.getElementById("00Nt0000000HwFm").value.length != 10)) {         helperMsg += "Please enter a valid phone number or email \n \r";             } else {                 if(email.length > 80) {                     //check of the length of the email is more than 80 characters                     helperMsg += "\n- Email cannot be more than 80 characters";                 }             }             if(helperMsg.length > 0) {                 alert(helperMsg);                 helperMsg = "";                 return false;             }             return true;         }         //validates a passed text string for email format         function checkEmail(str) {             var at = "@";             var dot = ".";             var lat = str.indexOf(at);             var lstr = str.length;             var ldot = str.indexOf(dot);             if(str.indexOf(at) == -1) {                 return false;             }             if(str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {                 return false;             }             if(str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {                 return false;             }             if(str.indexOf(at, lat + 1) != -1) {                 return false;             }             if(str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {                 return false;             }             if(str.indexOf(dot, lat + 2) == -1) {                 return false;             }             if(str.indexOf(" ") != -1) {                 return false;             }             return false;         }          function checkAge() {             var dateString = document.getElementById("dateInput").value;             //alert(dateString );             if(dateString != "") {                 var today = new Date();                 var birthDate = new Date(dateString);                 var age = today.getFullYear() - birthDate.getFullYear();                 var m = today.getMonth() - birthDate.getMonth();                 var da = today.getDate() - birthDate.getDate();                 if(m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {                     age--;                 }                 if(m < 0) {                     m += 12;                 }                 if(da < 0) {                     da += 30;                 }                 if(age < 15) {                     helperMsg += "Applicant cannot be younger than 15 years old \n\r";                 }                 // Removed by SH for US W-001991                 // else if (age > 39) { helperMsg += "Applicant cannot be older than 39 years old \n\r"; }                 dateString = "";             }         }          function checkHt() {             console.log("checking height");             var ht = document.getElementById("00Nt0000000H0l1").value;             if(ht < 56 || ht > 90) {                 helperMsg += "Please enter your height between 56 and 90 inches \n\r";             }         }         </script>         <!-- END VALIDATION RULES -->

1 respuesta
  1. 29 ago 2022, 18:15

    Hello,

     

    Have you tried this without the validation?

     

    It would be good to rule out if this works without your custom validation to identify that as the issue. 

0/9000