Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show google recaptcha error message with javascript

After validation, if captcha is not selected, a response is returned with g-recaptcha-response.

Because there is a dash in g-recaptcha-response, I can not display it

if (response.data.msg.g-recaptcha-response) {
document.getElementById('captcha').innerText = response.data.msg.g-recaptcha-response
}

1 Answers

Create a span or div tag where you want to display the message. Here I have just put it under the captcha box.

<div class="g-recaptcha">
</div>
<span id="error-captcha"></span>

Then validate with the script below and append the validation message to it:

if(grecaptcha.getResponse().length == 0){
     $('#error-captcha').empty()
     $('#error-captcha').append("Please tick the recaptcha.");
    }
like image 139
angela Avatar answered Sep 18 '26 20:09

angela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!