0

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.

1 Answer 1

1

Simplest way I can think of (I think this will work; anyone correct me if it is wrong):

<input class="form-check-input" type="checkbox" id="gridCheck1" required>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.