Salesforce for Google AdWords Blog

Salesforce for Google AdWords Blog

Web-to-Lead Form Validation

Kraig Swensrud Sep 25, 2007

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

Web_to_lead_form_validation_3

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">
<input type=hidden name="retURL" value="http://www.company.com/thanks.html">

      

<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) {
      
      
if(form.first_name.value == '') {

alert('Please enter your first name');
form.first_name.focus();
return false;
}


if(form.last_name.value == '') {

alert('Please enter your last name');
form.last_name.focus();
return false;
}

if(form.email.value == '') {

alert('Please enter your email address');
form.email.focus();
return false;
}


if(form.company.value == '') {

alert('Please enter your company');
form.company.focus();
return false;
}

return true;
}


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

 

5 Comments

matt

Tried this, but didn't work. Any ieas why this would not work?

Rino B.

I've done in this way and it works really very well!
Thank you for help.

Mark

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

John

This does not work with custom fields. HELP!

Carrie

Does anyone have a best practice on what a company should do when they receive a bad email address?

Post a comment