Python Flask - Access Form data -
i building simple python flask application. have validation page structured follows - have table 3 column. need user make changes first 2 columns. third column simple concatenation of first 2 column values.
i have constructed table follows:
<form action="http://localhost:5000/validation_form_submission" method="post" id="form1"> {% set count = 1 %} {% lines in res %} //res object passing python method linked page (its list of lists) <tr> <td><input id="{{ count|string + 'cola' }}" name="{{ lines[0] }}" value="{{ lines[0] }}" type="text"> </td> <td><input id="{{ count|string + 'colb' }}" name="{{ lines[1] }}" value="{{ lines[1] }}" type="text"></td> <td><input id="{{ count|string + 'colc' }}" name="{{ lines[2] }}" value="{{ lines[2] }}" type="text"></td> {% set count = count + 1 %} </tr> {% endfor %} </form> <input type="submit" value="submit" form="form1">
this code works expected. used js write script concatenates values first 2 columns , updates 3rd column, on click of button. works expected.
however, challenge facing in getting form data back. have written following method form data:
@app.route('/validation_form_submission', methods = ['post', 'get']) def get_data(): d = request.form return jsonify(d)
this not give me form data back. how can data elements form? also, if want data 3rd column, what's best way that?
update: adding javascript code in case helps:
(note: learning js, may not elegant way of doing this)
<script> function concat_resp() { var count = []; (var = 1; <= 100; i++) { count.push(i); } var cola_val = []; var colb_val = []; var colc_val = []; for(var i=0;i<count.length;i++){ cola_val[i]= count[i].tostring() + "cola"; colb_val[i]= count[i].tostring() + "colb"; colc_val[i]= count[i].tostring() + "colc"; } (i = 0; <= count.length; i++) { cola_value = document.getelementbyid(cola_val[i]).value colb_value = document.getelementbyid(colb_val[i]).value document.getelementbyid(colc_val[i]).value = cola_value.concat(colb_value) } } </script>
thanks!
Comments
Post a Comment