I'm just new to python and pyramid and I'm struggling with how to process the results of a form containing multiple checkboxes in Pyramid.
Here is an excerpt from my form:
<p tal:repeat="category categories">
<input type="checkbox" name="selectedcategories" value="${category.id}"> ${category.name}<br/>
</p>
And here is how I am currently trying to iterate through and process the results:
selectedcategories=request.params['selectedcategories']
for categoryid in selectedcategories:
category = DBSession.query(Category).filter_by(id=categoryid).one()
article.categories.append(category)
As you may have guessed, I'm only getting a maximum of one checkbox recognized no matter how many I select on the form. Django has an option to return the results as a list, but I can't seem to figure out how to do that with Pyramid.
request.params
is a multidict. To retrieve multiple values, you can call its getall() method:
selectedcategories = request.params.getall("selectedcategories")
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