function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Derek MorschDerek Morsch 

Web-To-Lead Validation

Hello,

I have currently created the below web-to-lead form but I am having trouble with a couple things. What code/script would I need to input to ensure the email field does not allow email addresses from gmail, yahoo, hotmail, etc...? Also, how do I make certain fields like first name, last name, email, and web site required fields?

<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00Dc0000003kLYk">
<input type=hidden name="retURL" value="http://streamlinx.com/thank-you/">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="example@example.com(for privacy purposes)">                                    -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<label for="URL">Website</label><input  id="URL" maxlength="80" name="URL" size="20" type="text" /><br>

<input id="00N80000005owbR" name="00N80000005owbR" type="hidden"><br>

<input type="submit" name="submit">

</form>
Best Answer chosen by Derek Morsch
Ashish KeshariAshish Keshari
Yes - now it is working. Please remove all the alert statements. Use this code in header. thanks.
<head>
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	if((strValue.indexOf('gmail') > 0) || (strValue.indexOf('yahoo') > 0) || (strValue.indexOf('hotmail') > 0)){
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    return true;
}
</script>
</head>

 

All Answers

Ashish KeshariAshish Keshari
Hi Derek,
I have updated your code - this should serve both the purpose. You can customize further with your needs. 
Please mark resolved and best answer if this helps. thanks.
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	if(strValue.includes('gmail') || strValue.includes('yahoo') || strValue.includes('hotmail')){
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    return true;
}
</script>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" if="theForm">

<input type=hidden name="oid" value="00Dc0000003kLYk">
<input type=hidden name="retURL" value="http://streamlinx.com/thank-you/">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="example@example.com(for privacy purposes)">                                    -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input required="true" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  required="true" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="email">Email</label><input  required="true" id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<label for="URL">Website</label><input required="true" id="URL" maxlength="80" name="URL" size="20" type="text" /><br>

<input id="00N80000005owbR" name="00N80000005owbR" type="hidden"><br>

<input type="submit" name="submit" value="Submit Query" onclick="return checkEmailAddress();">

</form>

 
Derek MorschDerek Morsch
Ashish,

I have placed this code on a private page on my web site. The required fields are working great! However, the email address filtering is not working as it is allowing me to put in any email address I want.
Ashish KeshariAshish Keshari
Can you please send me a screen shot of the input and the error you are seeing or any alert ? thanks.
Derek MorschDerek Morsch
Attached are a screenshot of an instance where the required fields are working correctly and I'm getting an error code. Also attached is an instance in which I put a sample email address in with "gmail" in it and was allowed to submit the form. You will see our "thank you" page in the last screnshot.
User-added imageUser-added image
User-added image
Ashish KeshariAshish Keshari
Hi Derek,
Please use the below code and it should serve the purpose :)
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	if((strValue.indexOf('gmail') > 0) || (strValue.indexOf('yahoo') > 0) || (strValue.indexOf('hotmail') > 0)){
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    return true;
}
</script>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" if="theForm">

<input type=hidden name="oid" value="00Dc0000003kLYk">
<input type=hidden name="retURL" value="http://streamlinx.com/thank-you/">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="example@example.com(for privacy purposes)">                                    -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input required="true" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  required="true" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="email">Email</label><input  required="true" id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<label for="URL">Website</label><input required="true" id="URL" maxlength="80" name="URL" size="20" type="text" /><br>

<input id="00N80000005owbR" name="00N80000005owbR" type="hidden"><br>

<input type="submit" name="submit" value="Submit Query" onclick="return checkEmailAddress();">

</form>

 
Derek MorschDerek Morsch
Ashish,

I greatly appreciate your help and patience with this. Unfortunately this is still not working with the email field. It is allowing me to put in whatever email address I like. Would you like me to provide you with the link to the page so you can look into it yourself?
Ashish KeshariAshish Keshari
sure pls go ahead - for me both the above code worked. thanks.
Derek MorschDerek Morsch
The link is as follows http://streamlinx.com/w2l-form-testing/ the password is "streamlinx"
Ashish KeshariAshish Keshari
Hi Derek,
I see the code is present but since I cannot modify it - can you please try to put javascript alert statements to check whether the method 'checkEmailAddress()' is called or not. Also - put alert statements in the if conditions to check where exactly the code is not working.
Derek MorschDerek Morsch
Ashish,

I have never worked with JS before, so if you could please help me out with providing what you want me to add, that would be helpful.

Thank you.
Ashish KeshariAshish Keshari
No issues. I have put the code with alert statement. Use this one and then I can test again and see where it is breaking. thanks.
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    alert('Alert1: ' + emailAddress.value);
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	alert('Alert2: ' + strValue);
    	if((strValue.indexOf('gmail') > 0) || (strValue.indexOf('yahoo') > 0) || (strValue.indexOf('hotmail') > 0)){
    		alert('Alert3: ' + strValue);
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    alert('Alert4: Ending...');
    return true;
}
</script>
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" if="theForm">

<input type=hidden name="oid" value="00Dc0000003kLYk">
<input type=hidden name="retURL" value="http://streamlinx.com/thank-you/">

<!--  ----------------------------------------------------------------------  -->
<!--  NOTE: These fields are optional debugging elements. Please uncomment    -->
<!--  these lines if you wish to test in debug mode.                          -->
<!--  <input type="hidden" name="debug" value=1>                              -->
<!--  <input type="hidden" name="debugEmail"                                  -->
<!--  value="example@example.com(for privacy purposes)">                                    -->
<!--  ----------------------------------------------------------------------  -->

<label for="first_name">First Name</label><input required="true" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

<label for="last_name">Last Name</label><input  required="true" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>

<label for="phone">Phone</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

<label for="email">Email</label><input  required="true" id="email" maxlength="80" name="email" size="20" type="text" /><br>

<label for="company">Company</label><input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

<label for="city">City</label><input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

<label for="state">State/Province</label><input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

<label for="URL">Website</label><input required="true" id="URL" maxlength="80" name="URL" size="20" type="text" /><br>

<input id="00N80000005owbR" name="00N80000005owbR" type="hidden"><br>

<input type="submit" name="submit" value="Submit Query" onclick="return checkEmailAddress();">

</form>

 
Derek MorschDerek Morsch
Ok I have placed the code in the page.
Ashish KeshariAshish Keshari
I see the Javascript code is not even getting invoked and hence it's not working. Can you please check if you can place the below javascript snippet in the head tag. If this does not work - then we will have to do a realtime troubleshooting. 
<head>
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    alert('Alert1: ' + emailAddress.value);
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	alert('Alert2: ' + strValue);
    	if((strValue.indexOf('gmail') > 0) || (strValue.indexOf('yahoo') > 0) || (strValue.indexOf('hotmail') > 0)){
    		alert('Alert3: ' + strValue);
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    alert('Alert4: Ending...');
    return true;
}
</script>
</head>
Derek MorschDerek Morsch
The script has been added to the header of the page, I am now seeing the alerts when I fill out the form. Please let me know how you would like to proceed.
Ashish KeshariAshish Keshari
Yes - now it is working. Please remove all the alert statements. Use this code in header. thanks.
<head>
<script>
function checkEmailAddress() {
    var emailAddress = document.getElementById('email');
    if(emailAddress.value != ''){
    	var strValue = emailAddress.value;
    	if((strValue.indexOf('gmail') > 0) || (strValue.indexOf('yahoo') > 0) || (strValue.indexOf('hotmail') > 0)){
    		alert('mail Id cannot be from gmail, yahoo or hotmal...pls change...');
    		return false;
    	}

    }
    return true;
}
</script>
</head>

 
This was selected as the best answer
Derek MorschDerek Morsch
Perfect, thank you so much for your help.
Ashish KeshariAshish Keshari
Great - Can you please mark this as best answer and close it. thanks