我知道这个问题已经回答了,但我不明白。我是不熟悉Flask并共同开发聊天网站的人。这包括一个供用户登录的数据库
我的signup.html具有相当大的尺寸,所以我只包括我遇到麻烦的部分:
{% 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 %}
我的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")
}
}
我的python(同样,不是整个文件):
@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")
除非用户确实同意,否则我不想重定向到主页。如果他们不选中该复选框,我已经设置了JavaScript来弹出一些消息,我需要告诉服务器从js停止。有人可以帮忙吗?PS:我也可以使用另一种方式实现目标。另外,以防万一这可以帮助任何人解决我的问题,我正在使用引导程序。我不擅长html,所以有什么用。
我能想到的最简单的方法(我认为这会起作用;如果错了,任何人都可以纠正我):
<input class="form-check-input" type="checkbox" id="gridCheck1" required>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句