irfanpule / django-form-surveys

Django form survey is an application Django to easier create form survey and easy integrated for your project.
MIT License
56 stars 19 forks source link

Anonymous response redirected to login page #81

Closed sandstromviktor closed 7 months ago

sandstromviktor commented 7 months ago

When submitting an anonymous survey, the user gets rerouted to login page, which doesn't really make sense.

It is probably due to the success_url

class SurveyFormView(FormMixin, DetailView):
    template_name = 'djf_surveys/form.html'
    success_url = reverse_lazy("djf_surveys:index")

Suggestions: Add a customizable success page and redirect to that, or do not redirect and only display the success message.

irfanpule commented 7 months ago

Hi @sandstromviktor

Thanks for your report. I have received reports like this in email. Thank you for your advice. I'll fix this.

sandstromviktor commented 7 months ago

Great! I solved this temporarily by creating a custom class and overriding the form_valid function. As such

class CustomCreateSurveyFormView(CreateSurveyFormView):
    def form_valid(self, form):
        # Call the superclass's form_valid method to ensure the form is saved
        super().form_valid(form)
        return render(self.request, 'success.html', {
            'success_message': "Form sent successfully."})

but it involved some messing with the urls to make it work properly.

irfanpule commented 7 months ago

Hi @sandstromviktor I'm forget, now you can set SURVEY_ANONYMOUS_VIEW_LIST = True on settings.py to make behavior anonymous make sanse. This feature available on version 2.0.4 or lastest

ref https://github.com/irfanpule/django-form-surveys/pull/70 https://github.com/irfanpule/django-form-surveys/pull/73

I think success page still needed to handle SURVEY ANONYMOUS VIEW_LIST = False. So I will fix it.

irfanpule commented 7 months ago

Hi @sandstromviktor

I have finish this https://github.com/irfanpule/django-form-surveys/pull/87 look forward to the next release