Skip to content
Advertisement

value of checkbox python bottle

I am trying to retrieve the labels (or values) of the checkboxes that the user has selected and return them to a different page. This logic is working for text entries, select options, and radios, all of which are included in that same python post method (so I know the method is working) but I cannot get it to work with checkboxes.

***If I set the boxes to checked as default by inserting “checked” at the end of the input line in form.tpl, then the first movie is listed, but if another movie is referenced in results, then it throws an error saying the second movie is undefined.

***If I do not set the boxes as checked by default, the movies will not appear even when the user checks the box in the form and submits.

form.tpl:

JavaScript

test.py:

JavaScript

results.tpl:

JavaScript

Advertisement

Answer

The checkbox fields are coming through for me, but as either "on" or the value you provided (if checked) or None (if unchecked), which seems sufficient to infer the state. Here’s a minimal example of passing checked state through each page:

server.py

JavaScript

form.tpl

JavaScript

Output on the terminal after a couple of requests checking one or the other of the boxes:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement