[Fixed]-Issues handling 2 forms in same django template

1👍

You should use a different name for the UserContentForm and the BookForm, instead of calling them both form.

# User Content Form
if request.method == "POST":
    user_content_form = UserContentForm(request.POST)
    ...
else:
    user_content_form = UserContentForm()

# BookingOnline Form
if request.method == "POST":
    book_online_form = BookOnlineForm(request.POST)
    ...
# watch this indentation. In your question above it is incorrect.
else: 
    book_online_form = BookOnlineForm()

d.update({'doctor': doctor, 'clinic': clinic,'book_online_form': book_online_form, 'user_content_form': user_content_form})

You will have to replace form with the correct variable in the rest of the view and your template.

Ideally, you should use a prefix when including multiple forms in the same template. However, doing that will require additional changes in your template, as you have hardcoded the form fields (e.g <input ...>), instead of letting Django render them (e.g. {{ form.patient_name }}).

Leave a comment