I have a contact form, where the user gets to enter his name, phone, email and a feedback message. At the push of the submit button, I want to show a message in the html page, to inform him that the message has been recieved. How do achieve this? I was thinking of storing the message in a session, but it doesn't get displayed in the page. I cannot render the template, because so, at any refresh, the message gets sent again... below is my code:
@app.route('/contact', methods=["POST", "GET"])
def contact():
if session.get("username") is not None:
email, password = edit_user(session["username"])
session["error_message"] = " "
if request.method == "POST":
name = request.form["name"]
phone = request.form["phone"]
message = request.form["message"]
result = send_email(email, name, message, phone) #method to check the form data and to actually send it
if result == "Thank you for your message. We will get back to you shortly.":
error_message = _("Thank you for your message. We will get back to you shortly.")
session["error_message"] = error_message
return redirect(url_for("contact"))
return render_template("about/contact.html", error_message=session.get("error_message"), email=email)
else:
return redirect(url_for("login"))