I have a multiselect in html file like this:
<select multiple id="mymultiselect" name="mymultiselect">
<option value="1">this</option>
<option value="2">that</option>
<option value="3">other thing</option>
</select>
When I access the mymultiselect field in flask/python via:
request.form['mymultiselect']
or by using the request.args.get function it only returns one selected item. I’ve learned that to get all the selected items I have to add [] to the name of the field, like so:
<select multiple id="mymultiselect" name="mymultiselect[]">
<option value="1">this</option>
<option value="2">that</option>
<option value="3">other thing</option>
</select>
I can see by viewing the post data in firebug that this is working, but I anytime I try to access this field in flask/python it comes back as null or None.
How do you access these multiselect form fields that have “[]” at the end of their name? I’ve tried appending “[]” to the field name in the python code as well but that does not seem to work.
You want to use the
getlist()function to get a list of values:You do not need to add
[]to the name to make this work; in fact, the[]will not help, don’t use it at all.