recaptcha doesn't work in a component (LOAD)

157 views
Skip to first unread message

Tim Richardson

unread,
Mar 5, 2014, 3:51:59 AM3/5/14
to web...@googlegroups.com
I have a form in a component.
I add recaptcha like so:

form.element('table').insert(-1,TR('',form_captcha,''))


loading the component via a URL for its controller function works
but the component when loaded via LOAD doesn't display
I get this message in Firefox's web console:

"Invalid App Id: Must be a number or numeric string representing the application id."

Tim Richardson

unread,
Mar 5, 2014, 4:42:13 AM3/5/14
to web...@googlegroups.com


"Invalid App Id: Must be a number or numeric string representing the application id."

That message is relating to a facebook plugin, it's not the problem with recpatcha

Tim Richardson

unread,
Mar 5, 2014, 5:27:05 AM3/5/14
to web...@googlegroups.com
I get the recaptacha rendered if I use ajax=False


{{=LOAD('default','newsletter_signup.load',ajax=False,ajax_trap=False)}}

but form processing doesn't work.
that is, form.process().accpeted is never true and neither is form.errors

ajax_true does mean that form processing works, but after an error, the recaptcha is not visible.
book says ajax=False, ajax_trap=False means a normal form submission, but that's not what I'm seeing.
this is on trunk.

Paolo Valleri

unread,
Mar 5, 2014, 5:56:49 AM3/5/14
to web...@googlegroups.com
Hi,
Is it working without placing it in a component?
have you tried to disable the facebook plugin? I'm just wondering if there is a correlation between the two.

Paolo

Tim Richardson

unread,
Mar 5, 2014, 6:17:55 AM3/5/14
to


On Wednesday, 5 March 2014 21:56:49 UTC+11, Paolo Valleri wrote:
Hi,
Is it working without placing it in a component?
have you tried to disable the facebook plugin? I'm just wondering if there is a correlation between the two.

I removed the facebook plugin but it made no difference.
Yes, it works when not in a LOAD.
The generated code is very different between the working example and the LOAD. It seems that the Google javascript for recapture is not being executed when LOAD is used.
When it works (no LOAD) there is a quite of lot of injected code which is not present in the LOADed component. In Firebug, I'm told to "reload the page to get source for http:..www.google.com/recpatcha/..." so the <script> tag put in the view by web2py isn't actually working in LOAD

The best thing would be to get recaptcha working in a LOAD(ajax=True) component. Google has an ajax interface to recaptcha. I couldn't get it working but this is probably the best solution.

Alternatives (LOAD ajax=False) don't get my anywhere. ajax=False, ajax_trap=False is not useful since the request is sent back to the parent controller function, which knows nothing about the form defined in the controller function for the component.

Paolo Valleri

unread,
Mar 5, 2014, 9:06:07 AM3/5/14
to web...@googlegroups.com
I run a couple of tests and I got the same issues, I am try to figure out why the js library (recaptcha_canary.js) is not loaded at all

 Paolo


2014-03-05 12:17 GMT+01:00 Tim Richardson <t...@growthpath.com.au>:


On Wednesday, 5 March 2014 21:56:49 UTC+11, Paolo Valleri wrote:
Hi,
Is it working without placing it in a component?
have you tried to disable the facebook plugin? I'm just wondering if there is a correlation between the two.
I removed the facebook plugin but it made no difference.
Yes, it works when not in a plugin.
The generated code is very different between the working example and the LOAD. It seems that the Google javascript for recapture is not being executed when LOAD is used.
When it works (no LOAD) there is a quite of lot of injected code which is not present in the LOADed component. In Firebug, I'm told to "reload the page to get source for http:..www.google.com/recpatcha/..." so the <script> tag in the view by web2py isn't actually working in LOAD


The best thing would be to get recaptcha working in a LOAD(ajax=True) component. Google has an ajax interface to recaptcha. I couldn't get it working but this is probably the best solution.

Alternatives (LOAD ajax=False) don't get my anywhere. ajax=False, ajax_trap=False is not useful since the request is sent back to the parent controller function, which knows nothing about the form defined in the controller function for the component.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/H8dOum7kpPA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tim Richardson

unread,
Mar 5, 2014, 3:12:11 PM3/5/14
to web...@googlegroups.com


On Thursday, 6 March 2014 01:06:07 UTC+11, Paolo Valleri wrote:
I run a couple of tests and I got the same issues, I am try to figure out why the js library (recaptcha_canary.js) is not loaded at all

 Paolo



I've opened issues 1888 and I've worked out how to fix it (see code on the issue page). I'll make a PR today/tongith

Tim Richardson

unread,
Mar 5, 2014, 7:00:06 PM3/5/14
to
I've made the PR, but my knowledge of jquery/javascript is paleolithic so Paolo it would be great if you can look at it.
It works.
https://github.com/web2py/web2py/pull/389

Paolo Valleri

unread,
Mar 6, 2014, 2:29:40 AM3/6/14
to web...@googlegroups.com
I haven't tested, just an idea, instead of adding a new parameter, what about checking current.request.ajax ? 

 Paolo


2014-03-06 0:59 GMT+01:00 Tim Richardson <t...@growthpath.com.au>:
I've made the PR, but my knowledge of jquery/javascript is paleolithic so Paolo is would be great if you can look at it.
It works.
https://github.com/web2py/web2py/pull/389


On Thursday, 6 March 2014 07:12:11 UTC+11, Tim Richardson wrote:

Tim Richardson

unread,
Mar 6, 2014, 5:56:40 AM3/6/14
to web...@googlegroups.com


On Thursday, 6 March 2014 18:29:40 UTC+11, Paolo Valleri wrote:
I haven't tested, just an idea, instead of adding a new parameter, what about checking current.request.ajax ? 


I didn't know about that. Does that mean that the client_side parameter in redirect is redundant?

people may want to optionally use the ajax recaptcha API even in non-LOAD circumstances, since it probably gives faster perceived load times, so there is probably justification for the extra control that a parameter gives.
 However, perhaps the default can be changed to True in case of current.request.ajax.




LightDot

unread,
Mar 6, 2014, 7:33:20 AM3/6/14
to web...@googlegroups.com
Well, if people want to use ajax for the recaptcha, they can make a load component out of it. I think that the parameter really is redundant...

Anyway, thanks for spotting & fixing this.

Regards

Paolo Valleri

unread,
Mar 6, 2014, 11:22:56 AM3/6/14
to web...@googlegroups.com
I agree with lightdot, the parameter is redundant. 
Mind that recaptcha library is splitted into two files, the first one (challenge) internally load a second one (recaptcha_canary.js). You made the former to be loaded with "ajax", the second is loaded dynamically in both the cases. Moreover the real library belongs to the second file, the first one contains only a few line of code

 Paolo

Tim Richardson

unread,
Mar 6, 2014, 8:11:10 PM3/6/14
to


On Friday, 7 March 2014 03:22:56 UTC+11, Paolo Valleri wrote:
I agree with lightdot, the parameter is redundant. 
Mind that recaptcha library is splitted into two files, the first one (challenge) internally load a second one (recaptcha_canary.js). You made the former to be loaded with "ajax", the second is loaded dynamically in both the cases. Moreover the real library belongs to the second file, the first one contains only a few line of code

Going over my head a bit. It seems that in the non-ajax api the first Recaptcha script rewrites the document to inject the canary code, and this doesn't happen when the script is itself loaded via ajax (as in a component). How it works is up to Google, I just followed their ajax api.

It seems to me that
a) we could completely move to using the ajax API (so my new parameter is redundant since it's the only way we do it)
b) auto-detect ajax
c) let the developer choose

(c) may be a temporary solution until we know that it works. Plus, we already ask the developer to specify ajax functionality in other places, so I'm not sure it's a big deal.
Personally, I'd like to go with the new parameter, which has a safe default, mark it as experimental which is a licence to remove it, and revisit it after it's had wider testing.

As for 'people who want to use ajax can make a load component out of it', that was what I was confronted with, but then I thought "LOAD is a web2py feature, and a good one, so is Recaptcha. It's a bug that one doesn't work with the other."

edit: I'm going to copy the relevant part of this thread to the PR on github.



 

Michele Comitini

unread,
Mar 7, 2014, 7:47:13 AM3/7/14
to web...@googlegroups.com
If you can ajax LOAD a whole form you can use this to add a recaptcha easily:


2014-03-07 2:09 GMT+01:00 Tim Richardson <t...@growthpath.com.au>:


On Friday, 7 March 2014 03:22:56 UTC+11, Paolo Valleri wrote:
I agree with lightdot, the parameter is redundant. 
Mind that recaptcha library is splitted into two files, the first one (challenge) internally load a second one (recaptcha_canary.js). You made the former to be loaded with "ajax", the second is loaded dynamically in both the cases. Moreover the real library belongs to the second file, the first one contains only a few line of code
Going over my head a bit. It seems that in the non-ajax api the first Recaptcha script rewrites the document to inject the canary code, and this doesn't happen when the script is itself loaded via ajax (as in a component). How it works is up to Google, I just followed their ajax api.

It seems to me that
a) we could completely move to using the ajax API (so my new parameter is redundant since it's the only way we do it)
b) auto-detect ajax
c) let the developer choose

(c) may be a temporary solution until we know that it works. Plus, we already ask the developer to specify ajax functionality in other places, so I'm not sure it's a big deal.
Personally, I'd like to go with the new parameter, which has a safe default, mark it as experimental which is a licence to remove it, and revisit it after it's had wider testing.

As for 'people who want to use ajax can make a load component out of it', that was what I was confronted with, but then I thought "LOAD is a web2py feature, and a good one, so is Recaptcha. It's a bug that one doesn't work with the other."





 
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Richardson

unread,
Mar 8, 2014, 11:26:18 PM3/8/14
to web...@googlegroups.com


On Friday, 7 March 2014 23:47:13 UTC+11, Michele Comitini wrote:
If you can ajax LOAD a whole form you can use this to add a recaptcha easily:


For me, this doesn't work. It surely has the same problem ... the javascript doesn't execute when the form is LOADed (LOAD... ajax=True) and the only way of fixing that is to use recaptcha's ajax API.

Anyone who is interested can try trunk and Recaptcha(...ajax=True). I've indicated in the book patch that this argument is experimental, and that it  may disappear in favour of auto-detecting ajax or simply using the ajax api always,
Reply all
Reply to author
Forward
0 new messages