Reputation: 701
hello i have a simple html form with select option choose. I want after form submit the user get successfully message like this
<p>your request is complete</p>
in the position of html form.
and if user press refresh then html form
come back in page.
here the code :
<form action="" method="POST">
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<br>
<br>
<input class="btn btn-primary btn-lg btn-block" type="submit">
</form>
any idea ?I am stack now
I know this method action="other.html"
but I want to work in the some html page without create other html page.
Upvotes: 0
Views: 538
Reputation: 8525
from django.contrib import messages
if reuqest.method == 'POST':
form = FormName(request.POST)
if form.is_valid():
# Code here
# sSuccess message
messages.add_message(request,messages.SUCCESS,"your request is complete")
else:
# error message
messages.add_message(request,messages.WARNING,"your request is incomplete")
Upvotes: 1
Reputation: 611
you need django messages to do that
from django.contrib import messages
if form.is_valid:
#validating form here
messages.success("your request is complete")
#return redirect here
Upvotes: 1