J

ajax이용할때 구글캡챠V2(reCAPTCHA v2) 체크박스 리셋시키기

회원가입이나 글쓰기시 AJAX로 통신하다보면 검증값때문에 더이상 진행이 안될때 구글챕챠를 리셋하고 다시 인증해야하는 상황이 있습니다.

 

/plugin/recaptcha|recaptcha.user.lib.php

 

// 캡챠 HTML 코드 출력
function captcha_html($class="captcha")
{

    global $config;

    /*
    #hl=ko 표시는 언어지정가능
    */
    $html = '<fieldset id="captcha" class="captcha recaptcha">';
    //$html .= '<script src="https://www.google.com/recaptcha/api.js?hl=ko"></script>';
    $html .= '<script src="https://www.google.com/recaptcha/api.js?onload=onload_grecaptchaCallback&render=explicit"></script>';
    $html .= '<script src="'.G5_CAPTCHA_URL.'/recaptcha.js"></script>';
    $html .= '<div class="g-recaptcha" id="g-recaptcha" data-sitekey="'.$config['cf_recaptcha_site_key'].'"></div>';
    $html .= '</fieldset>';

    return $html;
}

 



/plugin/recaptcha|recaptcha.js 하단에 추가

var grecaptchaId;
var onload_grecaptchaCallback = function() {
    grecaptchaId = grecaptcha.render('g-recaptcha', {
      'sitekey' : document.querySelector('#g-recaptcha').getAttribute("data-sitekey"),
      'theme' : 'light' //dark
    });
};

 

초기화 시킬때는 자바스크립트로

grecaptcha.reset(grecaptchaId);

 

이렇게 해주시면 됩니다.

|
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
5년 전 조회 4,710
5년 전 조회 4,347
5년 전 조회 4,298
5년 전 조회 6,061
5년 전 조회 1.1만
5년 전 조회 1.5만
5년 전 조회 4,229
5년 전 조회 4,543
5년 전 조회 8,179
5년 전 조회 4,464
5년 전 조회 3,864
5년 전 조회 6,513
5년 전 조회 5,332
5년 전 조회 5,555
5년 전 조회 4,411
5년 전 조회 5,047
5년 전 조회 4,150
5년 전 조회 4,050
5년 전 조회 3,229
5년 전 조회 6,889
5년 전 조회 4,120
5년 전 조회 3,407
5년 전 조회 3,809
5년 전 조회 3,970
5년 전 조회 4,445
5년 전 조회 3,539
5년 전 조회 4,705
5년 전 조회 4,949
5년 전 조회 3,297
5년 전 조회 3,067