I know this question has been answered already but I do not understand. I am new to flask and co-developing a chat website. This includes a database for users to log in
My signup.html has a considerable size, so I will only include the part I'm having troubles with:
{% extends "base.html" %}
{% block title %} Sign up {% endblock %}
{% block content %}
<form method="POST" id="signupform" action="#" onsubmit="checkForm()">
<div class="form-group row">
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="gridCheck1">
<label class="form-check-label" for="gridCheck1">
I have read and agreed to the <a href="/TOS">Terms Of Service</a>
</label>
<small id="checkSmall" class="form-text text-muted"></small>
</div>
</div>
</div>
</form>
{% endblock %}
My javascript:
function checkForm() {
var isChecked = document.getElementById("gridCheck1").checked
if (isChecked == false) {
console.warn("TOS not agreed to")
document.getElementById("checkSmall").innerHTML = "Please agree to the TOS before continuing.";
} else {
console.log("Tos were agreed to")
}
}
My python (again, not the whole file):
@app.route("/signup", methods=["GET", "POST"])
def signup():
if request.method == "POST":
Name = request.form["Name"]
Email = request.form["Email"]
Password = request.form["Password"]
usr = users(Name, Email, Password)
acc = [Name, Email, Password]
for value in acc:
if len(value) == 0 or " "*len(value) == value:
flash(f"{value} cant be blank")
return redirect(url_for("signup"))
break
elif len(value) > 100:
flash(f"{value} cant be more then 100 chars")
return redirect(url_for("signup"))
break
db.session.add(usr)
db.session.commit()
flash("Signed up.")
return redirect(url_for('home'))
return render_template("signup.html")
I dont want to redirect to the home page unless the user actually agrees. I already have the javascript set up to pop a little message if they dont check that checkbox, and I need to tell the server to stop from the js. Could anyone help? PS: I could also use another way to acheive my goal. Also, just in case this can help anyone solve my problem, I'm using bootstrap. I'm not good at html, so anything helps.