0

I have a single form accepting some data from the user. And I have 2 submit buttons on the same html template. I used validate_on_submit to identify a submit click. But, how do I identify, which button was clicked, so that I can perform 2 different options for the two different button clicks??

My view.py is as follows:

@app.route('/user', methods=["GET", "POST"])
def user():

form = ProjectSelect()
if form.validate_on_submit():
   # How do we identify 2 different submits here?

return render_template('user.html',
                       form=form)

My user.html is as follows:

{% extends "base.html" %}
{% block content %}
<h1> Tool!</h1>
<h2>Select projects of interest</h2>
  <table border="2"><form action="" method="POST">
    {{form.hidden_tag()}}
    ====Get input here====
  <tr>
  <td>
     <p>  <input type="submit" value="Setup Alert!!">
     </p>
     <p>  <input type="submit" value="Delete Alert!!">
     </p>

  </td>
  </tr>
  </table>
...

PLease let me know if it is possible to distinguish between the 2 submits.

Django
  • 181
  • 2
  • 15
  • Multiple forms in the one case, multiple buttons on the same form in the other, but the idea is the same in both cases. Let me know if this doesn't make sense and I'll vote to re-open. – Sean Vieira Jun 26 '14 at 00:50
  • I know that one could use multiple forms. But is it possible to use the same for 2 buttons! I saw the other post earlier and this is not a duplicate! – Django Jun 26 '14 at 01:01
  • 3
    The trick in this case is at the bottom of the post - you can access `request.form['name-of-submit-buttons']` and see *which* one was submitted by checking the value. Does that make sense? – Sean Vieira Jun 26 '14 at 01:13

0 Answers0