Reputation: 11812
I am creating a signup form using django(1.10) allauth app. I have installed django-recaptcha app from - https://github.com/praekelt/django-recaptcha
The captcha is working but it is showing after the field 'Organisation' as I am calling the module after 'Organisation' field. Is there any way so that the field displays at the end after password field.
Forms.py
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Field
from ajax_select.fields import AutoCompleteSelectField, AutoCompleteField
from phonenumber_field.formfields import PhoneNumberField
from . import models
from captcha.fields import ReCaptchaField
class SignUpForm(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
phone_number = PhoneNumberField(label=_("Phone (Please state your country code eg. +44)"))
organisation = forms.CharField(max_length=50)
captcha = ReCaptchaField(attrs={'theme' : 'clean'})
signup.html
{% extends "account/base.html" %}
{% load i18n crispy_forms_tags %}
{% block head_title %}{% trans "Signup" %}{% endblock %}
{% block content %}
<h1>{% trans "Sign Up" %}</h1>
<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form|crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button class="btn btn-success" type="submit">{% trans "Sign Up" %} <span class="fa fa-chevron-right"></span></button>
</form>
{% endblock %}
SO reference -- Is there any solutions to add captcha to Django-allauth?
Screenshot --
The captcha needs to put after 'password again' field. Do I need to create sub class or something like that?
Any help is highly appreciated.
Upvotes: 3
Views: 445
Reputation: 11812
I had to overwrite the default one in this way
class SignUpForm(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
phone_number = PhoneNumberField(label=_("Phone (Please state your country code eg. +44)"))
organisation = forms.CharField(max_length=50)
email = forms.EmailField()
password1 = forms.CharField(max_length=20)
password2 = forms.CharField(max_length=20)
captcha = ReCaptchaField(attrs={'theme' : 'clean'})
May be this is not the nicest way but relief for time being. Please any suggestions are highly welcomed.
Upvotes: 0