CodeIgniter Forums
Generating multiple checkbox from database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Generating multiple checkbox from database (/showthread.php?tid=82573)



Generating multiple checkbox from database - humbucker - 07-25-2022

Hello

Is it possible to use the form helper 
Code:
form_checkbox
to generate a checkbox group of multiple values stored in my database ?
This would be used to generate a search filter sidebar, based on values stored in database.

If it's only possible to generate one checkbox tag at a time, what's the best approach to code this ?
I need to be able to retrieve the user selected values to tick or untick these checkboxes.

Thank you



RE: Generating multiple checkbox from database - ozornick - 07-26-2022

Use foreach. Set form method as GET. For edited fields use data in _GET or $settings['key'] default


PHP Code:
foreach ($settings as $k => $v) {
    echo form_checkbox(...); // Here  set array options with value, is checked...


Get values form in controller

PHP Code:
$request->getGet('settings_key'$settings['settings_key']); 



RE: Generating multiple checkbox from database - humbucker - 08-03-2022

Thank you, you pointed me in the right direction !