I've added a new custom field on web-to-lead form (consent to contact-picklist),I want a user to be able to submit only if consent to contact=yes, by default it will appear as 'NO' on the form. Any help would be really appreciated.


  Lead Consent to Contact: 
  <select id="00Nw0000003cnpk" name="00Nw0000003cnpk" title="Consent to Contact"> 
    <option value="No">No</option>
    <option value="Yes">Yes</option>
<input type="submit" name="submit"/><br/></ul> 

You can use client side scripting to validate the inputs. You can either use JavaScript or jQuery for this.

You can find the free jQuery Validation Plugin which can be used for validation at this link.

But in your case, it's a simple validation, you can achieve it using simple Javascript as well. You can refer this link to get started on this.

One more way is to create a validation rule on Lead in Salesforce, this will prevent invalid leads from being created, but Salesforce won't return anything in response, hence user won't know the outcome.


Your javascript code that you provided in comments has error, hence it won't work.You will need to do 3 things in your web to lead form

Change the Id of the Lead Consent field in the generated html to something readable, but make sure that you are not changing the value of name attribute.

Replace this below line in web to lead html

<select id="00Nw0000003cnpk" name="00Nw0000003cnpk" title="Consent to Contact">


<select id="leadconsent" name="00Nw0000003cnpk" title="Consent to Contact">

Add this below script in the form tag

<script type='text/javascript'> 
    function ValidateForm() { 
        if (document.getElementById('leadconsent').value == 'No') { 
            alert("Please change value YES for consent to contact"); 
            return false; 
        return true; 

And lastly, add this validation method to form tag i.e.

replace the below code

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


<form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" onsubmit="return ValidateForm()">
  • +1 jQuery would definitely be overkill for such a simple project. – sfdcfox May 14 '19 at 14:41
  • Thanks Vijay, I'll try to find a validation rule using jQuery to see if it serve the purpose hoping that Salesforce visual page supports jQuery as we use VF page for web-to-lead form, and we want to stop form submission at user end so creating VR in salesforce may not the best option. – Inniboy May 14 '19 at 15:08
  • I would recommend you to use javascript rather then going for jQuery (Same has been recommended by @sfdcfox as well). Updated answer with a link to sample solution, you can get started with that. – Vijay Ganji May 14 '19 at 15:17
  • <script language="JavaScript" type="text/javascript"> <script type='text/javascript'> function ValidateForm() { var helperMsg = ''; if (document.getElementById('Lead_Consent_to_Contact_c__c').value.length == 'No') { helperMsg += "Please change value YES for consent to contact \n\r"; } if (helperMsg.length > 0) { alert(helperMsg); return false; } return true; } </script> – Inniboy May 15 '19 at 10:28
  • 1
    @Inniboy Updated the answer with the script and other changes that are needed, make changes in your web to lead form as mentioned and it should work! – Vijay Ganji May 15 '19 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.