Web-to-Lead Form Validation
Sep 25, 2007Nobody gets excited about dirty data in a CRM implementation. One great way to keep your data clean is to implement client-side javascript validation with your web-to-lead forms. This is a valuable technique for ensuring that a user completes certain required fields before they can submit your form. Just be careful not to overdo it, implementing excessive form validation will annoy users and cause your conversion rates to drop, so consider any client side validation alongside your marketing objectives.
The Web-to-Lead Validation Call
Simply add the following onsubmit function call to your existing Salesforce web-to-lead forms as shown by green text in the example below. Please note that other javascript functions (such as placing an onclick function on your submit button) are not certified.
<form action="https://www.salesforce.com/servlet/servlet.WebToLead" method="POST" onsubmit="return validation(this);"> <input type=hidden name="oid" value="insert_your_oid_here"> <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="40" name="last_name" 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> <input type="submit" name="submit"> </form> |
The Validation Function
Then include a javascript validation function, either directly in your HTML header or by reference. For example:
function validation(form) { |
Certififed with Salesforce for Google AdWords
The techniques noted here are supported with standard web-to-lead forms
and are certified not to conflict with the website tracking provided by
Salesforce for Google AdWords. As always, please contact us with questions via email: sfga (at) salesforce (dot) com


Tried this, but didn't work. Any ieas why this would not work?
Posted by: matt | March 29, 2009 at 05:41 PM
I've done in this way and it works really very well!
Thank you for help.
Posted by: Rino B. | June 25, 2009 at 02:41 AM
I do not know where to paste the validation function form? Every time I paste the validation function it ends up being displayed on my website as the html. How do I add the function to the header or add it as a reference? Please help. Thanks
Posted by: Mark | July 27, 2009 at 11:00 AM
This does not work with custom fields. HELP!
Posted by: John | July 31, 2009 at 10:02 AM
Does anyone have a best practice on what a company should do when they receive a bad email address?
Posted by: Carrie | October 15, 2009 at 12:38 PM