J

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

· 2020-03-16 (월) 11:07:19 · 7419

회원가입이나 글쓰기시 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);

 

이렇게 해주시면 됩니다.

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
20-04-10 조회 6,704
20-04-05 조회 7,487
20-04-05 조회 6,704
20-04-05 조회 8,353
20-04-04 조회 7,558
20-04-03 조회 9,798
20-04-02 조회 7,710
20-04-02 조회 7,293
20-03-29 조회 7,239
20-03-28 조회 9,032
20-03-27 조회 1.6만
20-03-25 조회 1.8만
20-03-24 조회 7,152
20-03-23 조회 7,527
20-03-23 조회 1.1만
20-03-22 조회 7,426
20-03-20 조회 6,776
20-03-20 조회 9,539
20-03-19 조회 8,334
20-03-18 조회 8,594
20-03-16 조회 7,420
20-03-15 조회 8,048
20-03-14 조회 7,100
20-03-14 조회 6,980
20-03-14 조회 6,203
20-03-13 조회 9,928
20-03-12 조회 7,260
20-03-12 조회 6,312
20-03-12 조회 6,703
20-03-12 조회 6,908