diff --git a/formie/forms.py b/formie/forms.py index 41cc0d1..b6cea7f 100644 --- a/formie/forms.py +++ b/formie/forms.py @@ -227,6 +227,12 @@ def all_forms(): @auth.login_required def new_form(): if request.method == "POST": + acf: ACF = ACF(0) + if request.args.get("hide_results", "false") == "true": + acf |= ACF.HIDE_RESULTS + if request.args.get("disallow_anon_answer", "false") == "true": + acf |= ACF.DISALLOW_ANON_ANSWER + schema = request.json error = validate_schema(schema) @@ -236,7 +242,7 @@ def new_form(): try: schema_str = json.dumps(schema) # TODO: fetch original instead fields = decode_fields(schema) - form = Form(schema=schema_str, created_at=datetime.datetime.now(), creator_id=g.user.id) + form = Form(schema=schema_str, created_at=datetime.datetime.now(), creator_id=g.user.id, access_control_flags=acf.value) db.session.add(form) db.session.commit() create_model(str(form.id), fields).__table__.create(db.engine) diff --git a/formie/static/new_form.js b/formie/static/new_form.js index 02289e6..d082fde 100644 --- a/formie/static/new_form.js +++ b/formie/static/new_form.js @@ -1,5 +1,8 @@ let fields_div = document.getElementById('fields'); +let hide_results = document.getElementById('hide_results'); +let disallow_anon_answer = document.getElementById('disallow_anon_answer'); + var index = 0; function new_field() { @@ -71,7 +74,8 @@ function make_schema() { function submit_form() { let req = new XMLHttpRequest(); - req.open('POST', document.location.href, false); + const params = new URLSearchParams({"hide_results": hide_results.checked, "disallow_anon_answer": disallow_anon_answer.checked}); + req.open('POST', document.location.href + `?${params}`, false); req.setRequestHeader('Content-Type', 'application/json'); req.send(JSON.stringify(make_schema())); if (req.status === 400) { diff --git a/formie/templates/forms/new.html b/formie/templates/forms/new.html index 666c4a2..813e105 100644 --- a/formie/templates/forms/new.html +++ b/formie/templates/forms/new.html @@ -7,5 +7,7 @@ {% block content %}
- +