[Zope] Re: boolean help

Martijn Pieters mj@digicool.com
Sun, 10 Dec 2000 12:46:51 +0100


On Sat, Dec 09, 2000 at 01:29:41PM -0800, Robin.Lamb@stanfordalumni.org wrote:
> I hope you don't think this email innappropriate, but you were so kind
> in responding to a previous question that I posted on the zope mailing
> list that I thought I would direct this simple question to you alone.  

It flatters me that you think I may be able to answer your qeustions :)
But I would appreciate it if you do keep sending your questions to the
mailinglists instead of directly to me. If only so that other people can
benefit from any answers you get!

I have added the Zope list to recipients of this reply.

> I am new at programming and have been unable to code a boolean button
> into my Zope Portal registgration form that can recall the previous
> selection such that it can be de-selected.  Basically, I want to enable
> a user on my site to sign-up, flip a boolean on, log out, then later log
> back in and unflip that boolean.  It's the "unflip" that catches me.  I
> have been able to make the boolean reflect the fact that it is selected
> when the user logs back on, back I can't make it unselectable.  Here's
> the code I've got now that doesn't allow for de-selecting,
>
> <input type="checkbox" name="current_college_student"
>   <dtml-if" member.current_college_student"> 
>     checked
>   </dtml-if>
>    value="member.current_college_student">
> <b>Current College Student</b>
> 
> I guess I need to tell the database that if no value is entered, it
> should delete "member.current_college_student" from its records.  

I am not sure what your problem is here. 

Are you talking about the fact that if the checkbox isn't checked, that
the browser doesn't send *any* information about the field
'current_college_student'?

If so, you can check for it's absense with the DTML construct '<dtml-unless
current_college_student> .. </dtml-unless>. Or you could add a hidden form
field *before* the checkbox which defines a default, empty value, like so:

  <input type="hidden" name="current_college_student:default" value="">

You can of course put any other value in there. The browser will always
pass this back to Zope, and then you can test for the value of
current_college_student.

Hope this helps!

> It seems so simple, I'm almost embarrassed to post my question to the
> general zope mailing list.  

Well, it wasn't so simple that you could figure it out on your own. There
may be other people that struggle with this, and they would benefit from
your questions and the answers you may receive.

-- 
Martijn Pieters
| Software Engineer  mailto:mj@digicool.com
| Digital Creations  http://www.digicool.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------