Login Retreive lost passwordRegister
Search

Forum Index / Feedback / dbCheckBox

[ This topic is solved ]

  Steph 20 January 10 / 22:46  
Hello,

I'm really enjoying formhandler and it's saving me a lot of time. But I want to use dbCheckBox and I can't get it to work. Please can anyone help.

I have a table structure with 10 fields in called Option1, Option2, Option3 ... Option10. They are all defined as boolean (int length 1).

I want to show 10 check boxes (one for each field) with a tick if the field is true (1) and no tick if it is false (0) and the changed value saved in the appropriate field if the user ticks or unticks one of the boxes.

I am really stuck on getting this to work - I don't think I understand the parameters for dbCheckBox and would welcome any help.

Thanks.

  Remco van Arkelen (Admin) 21 January 10 / 07:00  
Hi Steph,

Thank you for using FormHandler!
dbCheckbox is not designed to work with your database-design, it's based on records, not columns.

Your database seems to be wrong, what if another option is needed? You'll need to alter your table, which is just wrong :)

My suggestion would be to redesign this table and declare your options as records:

table_options:
|id | option |
|-------------|
| 1 | Option 1|
| 2 | Option 2|
| 3 | Option 3|
| 4 | Option 4|
| 5 | Option 5|
| 6 | Option 6|
| 7 | Option 7|
| 8 | Option 8|
| 9 | Option 9|

In this way a new or existing option can easily be altered. Your dbCheckbox will look like this:

<?php
$form 
= new dbFormHandler();
// etc

$form->dbCheckbox'My options''options''table_options', array( 'id''option' ), 'ORDER BY option ASC'true );

// etc
?>


In case you want to continue with your (i.m.h.o. WRONG) databasedesign you can't use dbCheckbox and will need to declare an array with all fieldnames of your table. If you use MySQL the fieldnames of a table can be retrieved by running a query:


SHOW FIELDS FROM insert_table_name_here;


These records can be added into an array which can be used in FH's "checkbox" method.

Regards,
Remco

  Top


powered by PHP-GLOBE   © 2004 - 2010 FormHandler. All rights reserved.   -   Open source license