Reputation: 508
I've been able to get the recpatcha to show up properly and submit with my form that I want to put the captcha in front of but it validates no matter what you type into the recaptcha form.
Here's my wtforms class:
class MessageForm(Form):
reason_code = SelectField(u'Reason', [validators.Required(message=(u'A reason for contacting us must be selected.'))], default = -1, choices=[('', ''), ('0', 'Advertising'), ('1', 'Comments/Suggestions'), ('2', 'Support')])
reply_to = TextField(u'Email address', [validators.Required(message=(u'A reply to email address is required.')), validators.Email(message=(u'A valid reply to email address is required.'))])
message_body = TextAreaField(u'Message', [validators.Required(u'You must enter a message to submit this form.')])
captcha = RecaptchaField(u'Captcha', [validators.Required(u'You must properly fill in the Captcha to submit this form.')], public_key=esp_constants.DEV_RECAPTCHA_PUBLIC_KEY, private_key=esp_constants.DEV_RECAPTCHA_PRIVATE_KEY, secure=True)
I'm using App Engine and in my handler for this form I have this
def post(self):
message_form = MessageForm(self.request.POST, captcha={'ip_address': str(self.request.remote_addr)})
Anyone else know if there's something I'm missing? The RecaptchaField seems to have all the correct data (i.e. challenge_field, etc) once the form is posted.
Thanks for any suggestions.
Upvotes: 1
Views: 2699
Reputation: 508
I ended up having to roll my own to get the combination of WebApp2, Recaptcha and WTForms working reliably in Google App Engine
This is basically how I handled it in as a validation method in my base controller
https://gist.github.com/mengelhart/8045030
The recaptcha HTML fragment looks like this:
https://gist.github.com/mengelhart/8045070
As for the recaptcha field value I used a standard HiddenField instead of the RecaptchaField type like this:
captcha = HiddenField("ReCaptcha")
Cheers
Upvotes: 1
Reputation: 147
Flask-WTF has support for Recaptcha (see https://flask-wtf.readthedocs.org/en/latest/), so perhaps their code might help you (in particular: https://github.com/lepture/flask-wtf/tree/master/flask_wtf/recaptcha).
Upvotes: 2