title: How to add confirmation dialog for POST request with Flask?
body: <p>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.</p>
  
  <p>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</p>
  
  <p>main.html</p>
  
  <pre><code>&lt;form class="module-form pure-form pure-form-aligned" autocomplete="off" id="uguu"&gt;
  &lt;fieldset&gt;
     &lt;div id="export-settings" class="module-block insight-border"&gt;
           &lt;div class="pure-control-group"&gt;
              {{ form.export_server.label }}
              {{ form_input(form.export_server, maxlength=255) }}
           &lt;/div&gt; 
           &lt;div class="pure-control-group"&gt;
              {{ form.export_port.label }}
              {{ form_input(form.export_port) }}
           &lt;/div&gt;
           &lt;div class="submit-button-group"&gt;
              &lt;button class="pure-button pure-button-primary" type="submit" 
                      formaction="confirm" formmethod="post"&gt;Apply&lt;/button&gt;
              &lt;button class="pure-button pure-button-primary cancel" type="submit"
                      formaction="config" formmethod="get"&gt;Cancel&lt;/button&gt;
            &lt;/div&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is the code segment in the flask server</p>
  
  <pre><code>@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) 
  </code></pre>
  
  <p>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. </p>
  
  <pre><code>&lt;div&gt; Are you sure kind of dialog? &lt;/div&gt;
  &lt;form&gt;
     &lt;button class="pure-button pure-button-primary deny" type="submit"  
                  formaction="config" formmethod="get"&gt;Cancel&lt;/button&gt;
  
     &lt;button class="pure-button button-warning confirm" type="submit" 
                  formaction="config" formmethod="post"&gt;Confirm&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>