chihung
10/18/2019 - 2:05 AM

add google Capcha and disable submit button

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
                                <div class="paragraph g-recaptcha" data-callback="clearcall" data-sitekey="6Le85bYUAAAAACzpJX6ZxSXMWs6AEbJzy9VbMkta"></div>
                                <script type="text/javascript">
                                    function clearcall(code) {
                                        if (code !== "") {
                                            $('[type="submit"]').removeAttr("disabled");
                                        }
                                    }
                                </script>


                                <p class="paragraph">
                                    <input type="submit" value="送信" class="wpcf7-form-control wpcf7-submit" disabled/>
                                </p>
    /* ReCAPTCHA */
    $captcha;
    if (isset($_POST['g-recaptcha-response'])) {
        $captcha = $_POST['g-recaptcha-response'];
    }
    if (!$captcha) {
        $message_array["error"][] = "please check CAPTCHA";
    } else {
        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6Lc87xETAAAAAPytkc_OHneFBMjViXYDLYEPAukT&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
        if ($response . success == false) {
            $message_array["error"][] = "spam";
        }
    }