Hi
this confused me too. The problem is that that checkboxes in html do
not return anything when submitted unless they are checked. You need
to check web.input() for an entry corresponding to the name of the
checkbox. If there is no entry, then interpret this as unchecked. In
your example replace your return statement with the following:
'''return "Results: %s, %s" % (form['A'].get_value(),
form['B'].get_value())'''
formdata = web.input()
return formdata.has_key('A'), formdata.has_key('B')
regards
ML
On Dec 18 2009, 3:08 pm, "W. Martin Borgert" <[email protected]>
wrote:
> Quoting "Anand Chitipothu" <[email protected]>:
>
> > Reported a bug.
>
> >https://bugs.launchpad.net/webpy/+bug/498135
>
> > I fixed the exception. Try using the latest trunk.
>
> >http://github.com/webpy/webpy/commit/43add10136eb503618116b3df683cae2...
>
> Many thanks!
>
> > Checkboxes are tricky. They have an attribute called value, which is
> > different from its value.
> > In 0.32,checkbox.value used to return its value and 0.33 returns the
> > value of attribute "value" and get_value() returns the actual value
> > that is the checked status.
>
> I see, but it doesn't work for me with 0.33. With the following
> code I get always "False, True" (the original values) as result,
> independent of the user input:
>
> import web
>
> template = '<form name="main" method="post">%s<input type="submit"/></form>'
>
> urls = ('/', 'index')
> app = web.application(urls, globals())
>
> myform = web.form.Form(web.form.Checkbox('A', checked=False),
> web.form.Checkbox('B', checked=True))
>
> class index:
> def GET(self):
> form = myform()
> return template % form.render()
>
> def POST(self):
> form = myform()
> if not form.validates():
> return template % form.render()
> else:
> return "Results: %s, %s" % (form['A'].get_value(),
> form['B'].get_value())
>
> if __name__=="__main__":
> web.internalerror = web.debugerror
> app.run()
>
> How do I get the checked status of thecheckbox?
>
> Thanks in advance!
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.