durusmail: quixote-users: Re: Getting empty checkboxes from request
Getting empty checkboxes from request
2003-12-18
Re: Getting empty checkboxes from request
2003-12-18
Re: Getting empty checkboxes from request
Graham Fawcett
2003-12-18
Thomas Guettler wrote:

> Hi!
>
> I think you all now the problem:
> You have a checkbox in a form, and you
> don't know if the checkbox set or not, since
> the browser don't send you values for
> unchecked boxes.
>
> request.form.get("mycheckbox")
> will return None in both cases:
>  1. The value was not displayed in
>      the HTML form (the user could not check it)
>  2. The value was displayed and
>     not checked by the user.
>
> I help me by adding a hidden form element "mycheckbox:savebool"
>
> You have the same problem, when you want to display
> a multiselect field with several single checkboxes.
>
> How do you handle this?

I assume you are displaying "mycheckbox" under certain known conditions.
Can't you test for those same conditions when you are processing the
form response?

For example, imagine that 'mycheckbox' appears in the Security section
of your form, and you didn't display the Security section because
request.session.user is not an Administrator. When processing the
response, test whether request.sesison.user is an Administrator. If
true, then you know that mycheckbox was displayed.

If necessary, you could send this state information to the client:

   

Perhaps that is what you are already doing with your
"mycheckbox:savebool"? It might be helpful to have the flag apply to a
whole section of a form, rather than to an individual element.

Best wishes,

-- Graham



reply