I will do this in functions, so resources only get allocated if needed.

def captcha_form():
    return SQLFORM.factory(db.table.field1, db.table.field2,
Field("anti_spam", widget=captcha, default='')
def normal_form():
    return SQLFORM(db.table)

if docaptcha:
  form = captcha_form()
else
  form = normal_form()

Still having a problem with using recaptcha inside of ajax_trap. It works in
plug-ins as long as ajax_trap or ajax are false.

-Thadeus




On Sat, Nov 21, 2009 at 12:26 PM, mr.freeze <nat...@freezable.com> wrote:

>
> I know what you mean.  I don't think it's possible as the form is
> built SQLFORM's __init__ function.  You might have some luck
> dynamically building a collection of fields then passing them like so:
>
> form = SQLFORM.factory(*fields)
>
> On Nov 21, 11:56 am, Thadeus Burgess <thade...@thadeusb.com> wrote:
> > Mainly because I really get agitated when I have to do silly things such
> as
> >
> > if do_captcha:
> >     form = SQLFORM.factory(db.table.field1, db.table.field2,
> > db.table.field3, Field('anti_spam', widget=captcha, default=''))
> > else:
> >     form = SQLFORM(db.table)
> >
> > -Thadeus
> >
> > On Sat, Nov 21, 2009 at 11:49 AM, Thadeus Burgess <thade...@thadeusb.com
> >wrote:
> >
> > > How do you append a Field() to SQLFORM? Does not look like it is
> possible.
> >
> > > -Thadeus
> >
> > > On Sat, Nov 21, 2009 at 11:47 AM, Thadeus Burgess <
> thade...@thadeusb.com>wrote:
> >
> > >> I believe it is the way that SQLFORM looks for data in request.vars.
> >
> > >> It will look for a var with the name of the field...
> >
> > >> so
> >
> > >> Field('recaptcha', widget=captcha)
> >
> > >> It is expecting a request.vars.recaptcha, which does not exist.
> >
> > >> You're right, setting default does fix it, sounds like a bug...
> >
> > >> So it seems that by setting a default, it is allowing SQLFORM to
> proceed,
> > >> even though it is not getting anything from request.vars.
> >
> > >> I even tried setting the field name to recaptcha_response_field with
> no
> > >> luck, but the default trick works! Lol you're awesome Freeze
> >
> > >> -Thadeus
> >
> > >> On Sat, Nov 21, 2009 at 11:34 AM, mr.freeze <nat...@freezable.com>
> wrote:
> >
> > >>> uld be able to create a form using SQLFORM(db.table) and then
> > >>> > insert the recaptcha field aft
> >
> >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to