You need to sign in to do that
Don't have an account?
Enable Submit button based on reCAPTCHA results
I am trying to use the new reCAPTCHA capability on a Web-to-Lead contact form that is being displayed on a Weebly website. I would like to enable my Submit button based on successful result form the reCAPTCHA. Right now, the user can still click the Submit even if they haven't check the reCAPTCHA checkbox. A lead isn't actually created, which is good, but it just goes on to my "Thank you" page, giving the user the impression they have submitted their contact info.
Here is the HTML at the end of my Web-to-Lead form that handles the reCAPTCHA. callValidation() is a function that checks to see whether the user has entered required fields in the form.
I'm not an HTML/Javascript wizard. Can anyone help me?
TIA!
Here is the HTML at the end of my Web-to-Lead form that handles the reCAPTCHA. callValidation() is a function that checks to see whether the user has entered required fields in the form.
<div class="g-recaptcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></div><br> <div id="button"> <input id="sell_house_submit" type="submit" name="submit" value="Get My Free Quote!" onclick="return callValidation();"> </div>
I'm not an HTML/Javascript wizard. Can anyone help me?
TIA!
All Answers
1) added the data-callback function in the CAPTCHA div above and given it a name "recaptcha_callback".
2) added the ' disabled="disabled" ' attribute to the input tag. This disables the input field by default. You can also do this in jQuery but for this purpose, the above is more than sufficient.
3) removed the onclick function, which is no longer necessary given the data-callback function.
In your JS script, you can then add the "recaptcha_callback" function as follows: This function removes the "disabled" attribute from your input submit field only after the reCaptcha data-callback is complete.
If you want to go the extra mile, I'd recommend some CSS to change the look and feel of the button to grey and unclickable (so as to not confuse the user). The following CSS would do the basic trick for the inactive state:
I used Lori's solution now which works. But thank you again for your time!
I tried to add this to the web to lead form:
For me, disabling the submit button and enabling it when user checks the reCaptcha etc is working fine. But, the leads are not being created in Salesforce after submitting the forms. Please Help!!!
<script type="text/javascript">
function recaptcha_callback() {
console.log('contact callback');
jQuery( "#submit-contact" ).prop( "disabled", false );
};
</script>
<input disabled="disabled" id="submit-contact" name="submit" type="submit" value="Submit">