when someone subscribes to the newsletter i automatically want to remove the popup for the user that just subscribed, i tried create a subscribed = False
then change it to subscribed = True
when a user subscribes. but it doesnt work. i can easily achieve this is a user is logged i, but in this case even unauthenticated users can also subscribe to the newsletter so that is where the issue comes in.
views.py
JavaScript
x
11
11
1
subscribed = False
2
if request.method == "POST":
3
form = NewsLetterForm(request.POST)
4
if form.is_valid:
5
form.save()
6
messages.success(request, f"Subscription Successfull, Thank you!! - Now check your mail")
7
subscribed = True
8
return redirect('/')
9
else:
10
form = NewsLetterForm()
11
templates.html
JavaScript
1
9
1
{% if subscribed != True %}
2
<p class="mb-0">Subscribe to our <b>NewsLetter</b></p>
3
<form class="form-inline" method="POST">
4
{% csrf_token %}
5
{{form.email}}
6
<button type="submit" class="btn btn-success-soft btn-sm" type="submit">Get Now</button>
7
{% endif %}
8
9
Advertisement
Answer
Django Close Bootstrap Modal On Submit
this solved my question for me, i had to do was close it when a user submits the form