Using recaptcha in rails without gem

To use google recaptcha in your application you need to obtain a key value pair which includes public and private key 
 
To get the the keys click here https://www.google.com/recaptcha/intro/index.html
 
It will redirect you to google reCAPTCHA home page -> Get reCAPTCHA -> fill the form where label is the label for your 
site and domain is the domain name of your site.

then you will get the keys site key and secret key.Now put this where you want the google recaptcha 
 <script src='https://www.google.com/recaptcha/api.js'></script>
 <div class="g-recaptcha" data-sitekey="site-key"></div> 
Then you will get the button like this.
Then clicking on the checkbox will open a default select image box:  
This verify callback will give you the response which is handled with an ajax call in rails or it can be used in any kind of application.

<script type="text/javascript">
    var verifyCallback = function (response) {
        $.ajax({
            method: 'POST',
            dataType: 'html',
            url: '<%= '#' %>' 
 })
};

    var onloadCallback = function () {
        grecaptcha.render('grecaptcha', {
            'sitekey': '#',
            'callback': verifyCallback 
 }); 
};

</script> 
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer>
</script>
<div id="grecaptcha", class="grecaptcha pull-right"></div>

Comments

Popular posts from this blog

Installing Wowza Streaming Engine on ubuntu

Highcharts with grouped categories

Completely Uninstall and Install Rubymine on ubuntu