I think you should'nt call Recaptcha with  'PUBLIC_KEY' and 'PRIVATE_KEY' 
as strings
PUBLIC_KEY and PRIVATE_KEY should be variables that contain the keys you 
have created on recaptcha website (
https://www.google.com/recaptcha/admin/create)

On* models\db.py* I would remove the line
db.contact_us.captcha = Recaptcha(request,
    'PUBLIC_KEY', 'PRIVATE_KEY')

And on *views/default/contact_us.html *I would replace 
<td colspan=2>{{=DIV(Recaptcha(error_message='invalid', label='Verify:', 
options='theme:"white", lang:"fr"'))}}
            </td>

*with*
*
*
<td colspan=2>{{=Recaptcha(request, PUBLIC_KEY, PRIVATE_KEY, 
error_message='invalid', label='Verify:', options='theme:"white", 
lang:"fr"')}}</td>


Or you could also add in your controller something lilke : 
form.element('table').insert(-1,(T('Please confirm that you are not a 
machine :'),Recaptcha(request, PUBLIC_KEY, PRIVATE_KEY),''))



Le vendredi 26 avril 2013 05:54:24 UTC+2, 黄祥 a écrit :
>
> hi
>
> is it possible to use recaptcha in custom forms?
> i've already tested it but it return an error :
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
>
> Traceback (most recent call last):
>   File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in 
> restricted
>     exec ccode in environment
>   File 
> "/home/stifank/Desktop/web2py/applications/stifix/views/default/contact_us.html",
>  line 164, in <module>
>   File "/home/stifank/Desktop/web2py/gluon/tools.py", line 732, in __init__
>     self.remote_addr = request.env.remote_addr
> AttributeError: 'NoneType' object has no attribute 'env'
>
>
> the things that i've done :
> *models/db.py*
> db.define_table('contact_us',
>     Field('name', notnull=True),
>     Field('email', notnull=True),
>     Field('phone', notnull=True),
>     Field('address', 'text', notnull=True),
>     Field('city', notnull=True),
>     Field('messages', 'text', notnull=True),
>     format='%(email)s %(name)s')
>
> from gluon.tools import Recaptcha
> db.contact_us.captcha = Recaptcha(request,
>     'PUBLIC_KEY', 'PRIVATE_KEY')
>
> *controllers/default.py*
> def contact_us():
>     form=SQLFORM(db.contact_us)
>     if form.process().accepted:
>         response.flash = T('messages sent')
>     elif form.errors:
>         response.flash = T('there is an error in the form')
>     else:
>         response.flash = T('please fill out the form')
>     return dict(form=form)
>
> *views/default/contact_us.html*
> {{=form.custom.begin}}
> <table>
>     <tbody>
>         <tr>
>             <td>{{=DIV(B(T(form.custom.label.name), SPAN(' *', 
> _style='color:red')))}}
>             {{=DIV(form.custom.widget.name)}}
>             </td>
>             <td>{{=DIV(B(T(form.custom.label.email), SPAN(' *', 
> _style='color:red')))}}
>             {{=DIV(form.custom.widget.email)}}
>             </td>
>         </tr>
>         <tr>
>             <td>{{=DIV(B(T(form.custom.label.phone), SPAN(' *', 
> _style='color:red')))}}
>             {{=DIV(form.custom.widget.phone)}}
>             </td>
>             <td>{{=DIV(B(T(form.custom.label.city), SPAN(' *', 
> _style='color:red')))}}
>             {{=DIV(form.custom.widget.city)}}
>             </td>
>         </tr>
>         <tr>
>             <td colspan=2>{{=DIV(B(T(form.custom.label.address), SPAN(' 
> *', _style='color:red')))}}
>             {{=DIV(form.custom.widget.address)}}
>             </td>
>         </tr>
>         <tr>
>             <td colspan=2>{{=DIV(B(T(form.custom.label.messages), SPAN(' 
> *', _style='color:red')))}}
>             {{=DIV(form.custom.widget.messages)}}
>             </td>
>         </tr>
>         <tr>
> *            <td colspan=2>{{=DIV(Recaptcha(error_message='invalid', 
> label='Verify:', options='theme:"white", lang:"fr"'))}}*
> *            </td>*
>         </tr>
>         <tr>
>             <td colspan=2>{{=DIV(form.custom.submit)}}
>             </td>
>         </tr>
>     </tbody>
> </table>
> {{=form.custom.end}}
>
> did anyone knows how to achieve it?
> thank you
>

-- 

--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to