html - Have unchecked checkbox yield a value in Django -



html - Have unchecked checkbox yield a value in Django -

i'm asking users of django app lot of yes/no questions, , i'd using checkboxes rather radio buttons. problem want value each checkbox, instead of each 1 checked.

i found trick using additional hidden checkboxes, looks nice hack, one of comments raised doubts in mind:

this not correct. both values submitted, html allows [multiple] values same name.

is true? if so, how django httprequest.post handle multiple values same name/key?

since html allows users submit multiple values single key, django has utilize specialized info construction accommodate possibility. result multivaluedict, request.get , request.post instances of under hood. can browse code construction here: http://djangoapi.quamquam.org/trunk/django.utils.datastructures.multivaluedict-class.html

the short story though can access first value simple dict lookup request.post['mykey'] , list of values request.post.getlist('mykey').

that said, other commenters have noted, there improve way handle utilize case describe. radio buttons yes/no alternative 1 solution, though perhaps less usable user's perspective. i'd think best way handle rethink how you're processing form, , using django forms library possible instead of doing low-level processing of raw post data.

html django webforms checkbox

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -