In my HTML file, I have:
<table>
{% for user in user_data_html %}
<tr>
<td>
<input id="firstname" name="firstname" type="text" value='{{ user.FirstName }}' />
</td>
<td>
<input name="submit" type="submit" value='update' />
</td>
</tr>
{% else %}
<tr><td>no user found</td></tr>
{% endfor %}
</table>
I want to modify the user name in the webpage by clicking update button in each row. But I always get the first "firstname" using the following python code in the backend:
firstname = request.form['firstname']
How can I solve this problem?
Forms get confused when you use the same name for each input name. You could either create a separate form around each table cell with the first name or you can use the jinja2 loop index to create unique input names...
<input id="firstname{{ loop.index }}" name="firstname{{ loop.index }}" type="text" value='{{ user.FirstName }}' />
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With