CRM Webform Email Validation
Hello!
I've been trying to use CRM Webforms to collect data about future leads on a landing page. However, I have stumbled upon a very big problem. The form does not actually validate that the e-mail that was filled in has a valid structure. I checked out the code for embedding the form into another website and found a possible typo in the validateEmail function and will post my solution here (though I'd rather it be fixed so I can embed the form into a Zoho Sites website without tinkering with the website's css directly) .
This is the function that the embed code generates in order to validate the structure of the email field (it only appears if there is an email field in your form):
function validateEmail()
{
var emailFld = document.querySelectorAll('[ftype=email]'); //potential problem here, since ftype is not an html attribute existing in the email field element
var i;
for (i = 0; i < emailFld.length; i++)
{
var emailVal = emailFld[i].value;
if((emailVal.replace(/^\s+|\s+$/g, '')).length!=0 )
{
var atpos=emailVal.indexOf('@');
var dotpos=emailVal.lastIndexOf('.');
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailVal.length)
{
alert('Please enter a valid email address. ');
emailFld[i].focus();
return false;
}
}
}
return true;
}
My own solution was replacing the selector for the email field
by replacing [ftype="email"] with [name="email"].
I'd like to know if there is a way for the CRM Webform to validate email structure when it is embedded directly in Zoho Sites from the Forms section when you add elements.
Thank you for your attention!