Error: ReCAPTCHA placeholder element must be empty

Nirali Joshi picture Nirali Joshi · May 4, 2016 · Viewed 54.8k times · Source

I am using recaptcha with my laravel application.

I just want to check recaptcha's response on form submit using jquery and stop user by alert that pleade validate captcha.

but , I could not stop form submission even if captcha is not filled.

here is my code.

 $('#payuForm').on('submit', function (e) {

                    var response = grecaptcha.getResponse();

                    if(response.length == 0 ||  response == '' || response ===false ) {
                        alert('Please validate captcha.');
                        e.preventDefault();
                    }
                });



<div class="captcha">
 {{ View::make('recaptcha::display') }}
</div>

I am getting this error in browser console , and form gets submit.

Error: ReCAPTCHA placeholder element must be empty

Answer

Waqas Bukhary picture Waqas Bukhary · Sep 3, 2016

You are loading the google recaptcha library twice.

https://www.google.com/recaptcha/api.js