Forum OpenACS Q&A: Checkbox Form t/f to database ...How?

I've been pounding my head against the monitor on this one...I'm getting tired and it's late.... Thanks in advance!

In /register/user-new.tcl I modified the Form and added a new opt in checkbox for a newsletter. I altered the users table to add a new field called update_newsletter_p char(1). In the tcl file I have:

...
(form method=post action="user-new-2.tcl")
...
#### My New Checkbox addition
(input type=checkbox name=update_newsletter_p value="f")
...
(input type=submit value="Register")
...

In /register/user-new2.tcl I add the new field to to the insert statement:

set insert_statement  "insert into users
(user_id,...update_newsletter_p...)
values ($user_id,... $update_newsletter_p, ...)"

I get two types of error messages:

If I DO NOT check the box:
Error: nsd.tcl: can't read "update_newsletter_p": no such variable

If I check the box (for 't')
Error: Ns_PgExec: result status: 7 message: ERROR: Attribute 't' not found

I read that "When a form is submitted, only the "on" checkboxes submit values to the server."

Soooo, How do I stuff a 't' or 'f' into the database from checkboxes on a form ?

-Bob

Collapse
Posted by Johannes Haas on
I would use one radio - button for true and one for false, because its boolean. There is a procedure

[press_radio_widget update_newsletter_p f "Yes"] 
[press_radio_widget update_newsletter_p t "No"]

where update_newsletter_p is the variable name, t / f is the value.

If you want to use just one selectbox you could write on the -2.tcl page s.th like:

if { ![info exists $update_newsletter_p] } {set update_newsletter_p "f"}

the insert should be like values (...'$update_newsletter_p',..)