python - django-recaptcha doesn't validate the input -


i trying integrate django-recaptcha django-registration. have make sure django-registration works. install , configure django-recaptcha according document (django-recaptcha 0.0.6).

i add captcha = recaptchafield() in registrationform class in registration/forms.py follow:

from captcha.fields import recaptchafield  class registrationform(forms.form):     required_css_class = 'required'     username = forms.regexfield(regex=r'^[\w.@+-]+$', max_length=30, label=_("username"), error_messages={'invalid': _("this value may contain letters, numbers , @/./+/-/_ characters.")})     email = forms.emailfield(label=_("e-mail"))     password1 = forms.charfield(widget=forms.passwordinput, label=_("password"))     password2 = forms.charfield(widget=forms.passwordinput, label=_("password (again)"))      captcha = recaptchafield()      ... 

the captcha show up, no matter typed in chptcha text (type nothing, correct, or incorrect), after press "bottom", shows "this field required." (of course have entered 2 password field).

captcha error

it should not private/public key problem incorrect setting captcha not show up, error text. idea?

btw, use python 2.7 django 1.4.3. , have tested 2 browsers: chrome , ie9.

[updated]

i found root cause of problem because text typed not pass post request shown follow:

post:<querydict: {u'username': [u'test123'], u'password1': [u'123'], u'csrfmiddlewaretoken': [u'buveurhlumydx1djztgdruk1cri7wany'], u'email': [u'test@gmail.com'], u'password2': [u'123']}>, 

the html source code shown on client browser displayed follow. should have "recaptcha_challenge_field" in post request, not sure why client browser not send out variable in post request. new java script. idea?

<!doctype html> <html>     <head>         <title>register account</title>     </head>     <body>  <table>     <form method='post' action=''><div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='buveurhlumydx1djztgdruk1cri7wany' /></div>         <tr class="required"><th><label for="id_username">username:</label></th><td><input id="id_username" type="text" name="username" maxlength="30" /></td></tr> <tr class="required"><th><label for="id_email">e-mail:</label></th><td><input type="text" name="email" id="id_email" /></td></tr> <tr class="required"><th><label for="id_password1">password:</label></th><td><input type="password" name="password1" id="id_password1" /></td></tr> <tr class="required"><th><label for="id_password2">password (again):</label></th><td><input type="password" name="password2" id="id_password2" /></td></tr> <tr class="required"><th><label for="id_captcha">captcha:</label></th><td><script type="text/javascript">     var djangorecaptchaoptions = {   "lang": "en" };     if (typeof recaptchaoptions !== 'object') {         recaptchaoptions = djangorecaptchaoptions;     } else {         (key in djangorecaptchaoptions) {             recaptchaoptions[key] = djangorecaptchaoptions[key];         }     } </script> <script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=6leuno4saaaaaadkacui6ybtispi-yhiloadgfnf&hl=en"></script> <noscript>   <iframe src="https://www.google.com/recaptcha/api/noscript?k=6leuno4saaaaaadkacui6ybtispi-yhiloadgfnf&hl=en" height="300" width="500" frameborder="0"></iframe><br />   <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>   <input type='hidden' name='recaptcha_response_field' value='manual_challenge' /> </noscript> </td></tr>         <tr><td></td><td><input type="submit" value="send activation email" /></td>     </form> </table>      </body> </html> 

i found answer! because of <table> tag in registration_form.html, 1 provided django-registration package. content is:

{% extends "registration/registration_base.html" %} {% load i18n %} {% block title %}{% trans "register account" %}{% endblock %} {% block content %} <table>     <form method='post' action=''>{% csrf_token %}         {{ form }}         <tr><td></td><td><input type="submit" value="{% trans "send activation email" %}" /></td>     </form> </table> {% endblock %} 

unfortunately, recaptcha has <table> tag embedded in java script, means there have recaptcha <table> tag inside registration_form <table> tag. though browser can correctly render page, however, not correctly retrieve field such "recaptcha_challenge_field" , "recaptcha_response_field" in embedded <table>

the solution remove <table> related tag registration_form.html.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -