How to post to allauth signup form to fill in initial data?

Viewed 608

I'm using django-allauth, and trying to use one form to fill in initial data on the signup form. So, say there is a form on the home page where you fill in your email address, and that form posts to the signup form, and we just want the email address you filled in to be set as the initial data for the second form.

The way I've been trying to do it is by extending the SignupView class:

class MySignupView(SignupView):

    def post(self, request, *args, **kwargs):
        if not request.POST.get('submit'):
            email_initial = request.POST.get("email_initial")
            self.initial = {"email":email_initial}
            form_class = self.get_form_class()
            form = self.get_form(form_class)
            return self.render_to_response(self.get_context_data(form=form))
        else:
            return super(MySignupView, self).post(self, request, *args, **kwargs)

I'm sure that the code after "if not request.POST.get('submit'):" is being run when I post to the signup form from the first form. I want email_initial to be set as the initial email on the signup form. The problem I'm having is that the second form is being validated as if it were submitted itself. This code:

    form_class = self.get_form_class()
    form = self.get_form(form_class)
    return self.render_to_response(self.get_context_data(form=form))

Is exactly the same as the code that gets run on GET for the form. I'm able to set initial data when overriding the GET function, but not the POST function. Is there any way to just display the form with some initial data on POST, without validating the form?

1 Answers
Related