Validate Google Captcha via JavaScript

Suppose You have Form Similar to the code below

<form id="myformId" class="col s12" action=""
        <input placeholder="Name" id="mpfaqs-form-fieldset-input" type="text" name="username">
        <input placeholder="Email" id="mpfaqs-form-fieldset-input" type="text" name="useremail">
            <input placeholder="What is your question" id="mpfaqs-form-fieldset-input-question"
                   type="text" name="userquestion">
    <div class="g-recaptcha" data-sitekey="YOURSITEKEYxxxxx"></div>
        <input class="form-submit" type="Submit" name="" value="Submit a question">
<script src=''></script>
<script src=''></script>

To Validate above Form through javascript we will use the the below code you can place it in the same file or create an external file for it and place the code

    ], function($) {

        $(document).on('submit', '#myformId', function(){
            var isSubmit = jQuery(this).valid() && grecaptcha.getResponse() != '';

            if (!isSubmit) {
                alert("Please fill captcha");
            return isSubmit;



Leave a Reply

Your email address will not be published. Required fields are marked *