First time with Flask. I am trying to add a confirmation dialog for a form but only on certain conditions. So I am not able to do this on the client side. I was able to add it for the GET request but I wasn't able to do it for POST requests because I need to pass around the form data. Here is what I have done.
This is the form submit of the main form. On Cancel, it just refreshes the data on the current page by doing get request for config. But on Apply, it issues a POST request to /confirm route
main.html
<form class="module-form pure-form pure-form-aligned" autocomplete="off" id="uguu">
<fieldset>
<div id="export-settings" class="module-block insight-border">
<div class="pure-control-group">
{{ form.export_server.label }}
{{ form_input(form.export_server, maxlength=255) }}
</div>
<div class="pure-control-group">
{{ form.export_port.label }}
{{ form_input(form.export_port) }}
</div>
<div class="submit-button-group">
<button class="pure-button pure-button-primary" type="submit"
formaction="confirm" formmethod="post">Apply</button>
<button class="pure-button pure-button-primary cancel" type="submit"
formaction="config" formmethod="get">Cancel</button>
</div>
</div>
</fieldset>
</form>
This is the code segment in the flask server
@config_page.route("/config", methods=["GET", "POST"])
def config():
if request.method == "POST":
return post_config() #Uses request.form
return get_config()
@config_page.route("/confirm", methods=["POST"])
def confirm():
with ClassA() as class_a:
class_a.load()
#Need to show the confirmation only on this condition
if class_a.is_val_x and request.form['is_val_x'] == 'on':
#Is this the right way to go about it?
return render_template('confirm.html', form=request.form )
return redirect(url_for('.config',form=request.form),code=307)
An finally the code segment in confirm.html. The get request works fine but I am not sure how to post the form data from the flask /confirm route to /config. I am not even sure if this is the right way to do it. Any help would be really welcome? Any solution possible in jQuery or javaScript is also welcome.
<div> Are you sure kind of dialog? </div>
<form>
<button class="pure-button pure-button-primary deny" type="submit"
formaction="config" formmethod="get">Cancel</button>
<button class="pure-button button-warning confirm" type="submit"
formaction="config" formmethod="post">Confirm</button>
</form>