0

So, basically in my flask application, i want to read all the element contents present inside table.

<form action="#">
<table >
        <tr> 
         <th><input type="text" id="txtName"/></th>
         <th><input type="text" id="txtAdd"/></th>
         <th>...</th>
         <th>...</th>
        </tr>
    
</table>
<button type="submit">Save Details</button>
</form>

Adding Flask code: Once the form is posted, i am reading all the elements one by one and here i want to read the HTML table embedded inside form as well.

@app.route('/EntityMaster', methods=['GET', 'POST'])
def EntityMaster():
    if request.method == 'POST':        
            entityname = request.form['entityname']
            address = request.form['address']
            region = request.form['region']           
            try:
                cur = flaskmysql.connection.cursor()
                cur.callproc("saveproc", [entityname, address, int(region)])
                results = cur.fetchall()
                cur.close()
            except:
                flash("Error occured during adding Entity", "alert-danger")                                            
Amol Kadam
  • 85
  • 1
  • 10

1 Answers1

1

On the client side (using javscript) scan the table and find the input elements <input>.

Collect the values and the ids into JSON.

Post the JSON (using XHR or Fetch) to a flask endpoint.

balderman
  • 22,927
  • 7
  • 34
  • 52
  • thanks @balderman. Is there any way by which i can read the contents of table elements just like any other elements at flask app side.. – Amol Kadam Sep 01 '20 at 15:58
  • @AmolKadam - the code must be running on the browser side using javascript. Use https://stackoverflow.com/questions/2214066/get-list-of-all-input-objects-using-javascript-without-accessing-a-form-object as a reference – balderman Sep 01 '20 at 16:00