I have a form that is populated with a list of image files that the user can delete. When the form is created, a Jinja loop iterates through the list of photo files and provides a preview of the image and a checkbox so the user can select which images to remove.
{% for elem in orphans %}
<input type="checkbox" id="op_checkbox_{{loop.index}}"></input>
<img src="{{ITEM_IMAGE_DIR}}{{elem}}" class="thumbnail" style="display:inline-block; max-width:230px; max-height:50px; width: auto; height: auto;">
{% endfor %}
When the form is POSTed to my Python app, I need to iterate through the list of checkboxes and determine which ones are checked. A hidden input returns the number of photos.
for i in num_items:
form_var = "op_checkbox_" + str(i)
if (request.form[form_var] == True):
This doesn’t work, obviously. However, I’ve been unable to determine what would…
What I tried was using a variable as the element part of the request.form[element]
What I expected was to be able to access the form elements.
I’m hoping someone has a solution. But if this isn’t the correct way to do this, an alternative method for accessing an arbitrary number of form variables would also work.