1

I want to customize my signup form and bring a new feature. The new feature is a signup form with two category. One is signup as a developer which will have one more field called experties and another a general signup which will have username, email, password and confirm password. I have done the general signup process but no idea on best way to handle another signup form. And they will be shown on the same page.

enter image description here

Signup form as a general user that i could do is

ACCOUNT_SIGNUP_FORM_CLASS = 'pages.custom_sign_up_form.CustomSignupForm'

custom_sign_up_form.py

class CustomSignupForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(CustomSignupForm, self).__init__(*args, **kwargs)

    def clean_email(self):
        email = self.cleaned_data.get('email')
        if settings.INVITE_MODE:
            invitation, _ = Invitation.objects.get_or_create(email=email)
            if not invitation.request_approved:
                self.add_error('email', 'Sorry at this time you are not invited. But we have added you to our invite list')
        return email

    def signup(self, request, user):
        user.save()

signup.html

<form class="ui form login" action="{% url 'account_signup' %}" method="POST">
          {% csrf_token %}
          <div class="field">
            {% if form.username.errors %}
              <div class="ui big left icon input error" data-tooltip="{{form.name.errors.0}}" data-position="right center">
            {% else %}
              <div class="ui big left icon input">
            {% endif %}
              <i aria-hidden="true" class="user icon"></i>
              <input type="text" name="username" class="form-control-ui" placeholder="Username">
            </div>
          </div>
          <div class="field">
            {% if form.email.errors %}
              <div class="ui big left icon input error" data-tooltip="{{form.email.errors.0}}" data-position="right center">
                      {% else %}
              <div class="ui big left icon input">
            {% endif %}
              <i aria-hidden="true" class="user icon"></i>
              <input type="text" name="email" class="form-control-ui" placeholder="Email">
            </div>
          </div>
          <div class="field">
            {% if form.password1.errors %}
              <div class="ui big left icon input error" data-tooltip="{{form.password1.errors.0}}" data-position="right center">
            {% else %}
              <div class="ui big left icon input">
            {% endif %}
              <i aria-hidden="true" class="asterisk icon"></i>
              <input type="password" name="password1" class="form-control-ui" placeholder="Password">
            </div>
          </div>
          <div class="field">
            {% if form.password2.errors %}
              <div class="ui big left icon input error" data-tooltip="{{form.password2.errors.0}}" data-position="right center">
            {% else %}
              <div class="ui big left icon input">
            {% endif %}
              <i aria-hidden="true" class="asterisk icon"></i>
              <input type="password" name="password2" class="form-control-ui" placeholder="Confirm Password">
            </div>
          </div>
          <div class="field">
            {% if redirect_field_value %}
            <input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
            {% endif %}
          </div>
          <button type="submit" class="ui big fluid button primary">Signup</button>
        </form>
pythonBeginner
  • 781
  • 2
  • 12
  • 27
  • There are two alternative solutions given here: https://stackoverflow.com/questions/44505242/multiple-user-type-sign-up-with-django-allauth/45934856#45934856 – Alex Gustafson Aug 29 '17 at 09:05

0 Answers0