1👍
Every individual form needs its own form.is_valid()
to be called to get its error fields in the template. In your post method there is only one form.is_valid(
) called, which is for RegistrationForm
only.Better send/receive three form independently. In the template, use them under one form.
Things could’ve been done this way:
views.py
if request.method == 'POST':
reg_form = RegistrationForm(request.POST)
contact_form = ContactForm(request.POST)
free_form = FeeForm(request.POST)
reg_valid = reg_form.is_valid()
contact_valid = contact_form.is_valid()
free_valid = free_form .is_valid()
if reg_valid and contact_valid and free_valid:
#Everything is fine, do the registration and go to success page
else:
#error happened, so go to form page with error fields
return render(request, 'registration/register.html', {'student' : student, 'reg_form' : reg_form,'contact_form' : contact_form, 'free_form' : free_form,'registration_status' : registration_status,'registration':registration })
else:
reg_form = RegistrationForm(initials=...)
contact_form = ContactForm(initials=...)
free_form = FeeForm(initials=...)
return render(request, 'registration/register.html', {'student' : student, 'reg_form' : reg_form,'contact_form' : contact_form, 'free_form' : free_form,'registration_status' : registration_status,'registration':registration })
Source:stackexchange.com