So I know how to use forms to fetch user input in python flask, however, I want to allow the user to input text in a window popup prompt (I can activate this in javascript), then send this data straight to flask on submission. The problem is that I don't know how to give flask this information since it is in the scope of javascript. May I please know how I can do this?
Thanks in advance!
Edit: MWE code (I hope this has enough detail.)
<!-- students.html -->
<form method="POST", action="/students">
<button name="remove_student_button" value={{ student.email }} onClick="myFunction()">Remove</button>
</form>
<script>
function myFunction() {
let person = prompt("Are you sure you want to remove this entry? Enter the student's email to confirm your action.");
if (person == null || person == "") {
// Cancelled. Nothing happens
} else {
// Run form method which activates /students.
}
}
</script>
# routes.py
@app.route("/students", methods = ["GET", "POST"])
def students():
# ...
if "remove_student_button" in request.form:
email = request.form["remove_student_button"]
student = Student.query.filter_by(email=email).first()
print(student.first_name)
db.session.commit()
flash("Student removed")
return redirect(url_for("students", student_removed=True))
# ...