using check boxes in a single page

Permalink
Hi,

I have created a package that contains a single dashboard page with also another single page for adding/editing entries. In the package is also a block that displays a div for each entry containing all the information from that entry.

This was a pain but is all working perfectly now.

What i would like to do is on the add/edit page i would like to add a check box that says reserved? If this is checked i would like a column in my database to be true and if unchecked would like it to be false.

Then if it is true that div in the block would and an overlay div with the word reserved on it.

I have done lots of googling but i can not find out how i can add a check box to the form on the add/edit page and then when that page is saved add or edit the column in the database.

Any ideas??

sparrowwebservices
 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi sparrowwebservices,

Here is some information about using checkboxes.
http://stackoverflow.com/a/34450628...

The link describes how to use a checkbox in a block. The process is similar when working with non-block controllers, with the exception that you have your own method to handle saving. I believe saving true and false as 1 and 0 is preferred.

To access the checkbox value in the block, you would select your data from the database in your block controller (commonly in the view() and edit() methods). You can then use the set() method to make the data available in your block form and view. Since you are working with multiple entries, you will likely be using set() with an array.
$this->set('entries', $entries);

- $entries is the results array from your database query

In your view, you would have the variable $entries available. Its value would be your entries array. As you looped through it, you could check the key that was used to hold the value of your entry checkbox. If it was 1, it was true, so you would conditionally add your overlay div to the entry.
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
Thanks yet again MrKDilkington,

Got it all working a treat :)