Hi,

I'm using Recaptcha with ajax, and in case it helps I have the following 
(programmed some time ago but still working):


> Include this in your layout.html ...

 <script type="text/javascript" src=
"http://www.google.com/recaptcha/api/js/recaptcha_ajax.js";></script>



> Include this somewhere in your model (where NUBE.captcha_hid is just a 
global id) ...

                # must use Recaptcha's AJAX api, otherwise document.write 
is being generated by google and breaks the dynamic/ajax calls.
                # 
http://code.google.com/apis/recaptcha/docs/display.html#AJAX
                def _nube_recaptcha_xml(self):
                    captcha = DIV(
                        DIV(_id=NUBE.captcha_hid),
                    )
                    if self.errors.captcha:
                        captcha.append(DIV(self.errors['captcha'], _class=
'error'))
                    return XML(captcha).xml()
                gluon.tools.Recaptcha.xml = _nube_recaptcha_xml



> Include this also in models ...

                auth.settings.captcha = gluon.tools.Recaptcha(
                    request,
                    keys[0], # PUBLIC key
                    keys[1], # PRIVATE key
                    use_ssl = False,
                    error_message = T('captcha_invalid'),
                    options = 'theme:"white"',
                )



> Include this in models too ...

    def captcha(self):
        return self.auth.settings.captcha

    def captcha_x(self, attr):
        obj = self.captcha()
        return getattr(obj, attr) if obj else ''

    def captcha_key(self): return self.captcha_x('public_key')
    def captcha_options(self): return self.captcha_x('options')



> Include this in web2py_ajax.html (where nube.wbox_centerifvisible is just 
a js function to center the modal window) ...

    var captcha_hid = '{{=NUBE.captcha_hid}}'
    var captcha_key = '{{=nube.captcha_key()}}'
    var captcha_options = { {{=XML(nube.captcha_options())}} }
    if (captcha_options) {
      captcha_options.callback = function(){ nube.wbox_centerifvisible(null) 
}
    }



> Include this somewhere in your javascript ...

 w_wcaptcha: function(w) { return w.find('#'+captcha_hid) },

 w_wcaptcha_open: function(w) {
 var wcaptcha = this.w_wcaptcha(w)
 if (wcaptcha.length) {
 // http://code.google.com/apis/recaptcha/docs/display.html#AJAX
 // http://code.google.com/apis/recaptcha/docs/customization.html
 Recaptcha.create(captcha_key, captcha_hid, captcha_options)
 }
 },

 // execute this when opening captcha via ajax (where "w" can be the modal 
window).
 this.w_wcaptcha_open(w)



The above does not have any specific order, and some code is included in 
classes (python and js) and such.

You might be able to simplify the above depending on your specific case.

Hope this helps ...

   Carlos


On Friday, May 25, 2012 6:50:52 PM UTC-5, weheh wrote:
>
> For completeness, please refer to:
>
>
> https://groups.google.com/forum/?fromgroups#!searchin/web2py/recaptcha$20load$20ajax/web2py/9retDkkyGxU/p6j_F3U8X3YJ
>
>
> https://groups.google.com/forum/?fromgroups#!searchin/web2py/recaptcha$20load$20ajax/web2py/eeMT2Bb-KYA/7G6WZ-XeIygJ
>
> This is an old issue and I'm late to the game, but with my modular 
> approach I'm seeing that pbreit has already explored this 
> javascripted-initial-authentication territory and declared it inhospitable.
>
> Basically, if I'm to understand, you can't use Recaptcha with LOAD(..., 
> ajax=True). Am I right?
>

Reply via email to