简体   繁体   中英

Getting Data from Database Populated Checkbox Array

I recently created a View that included code to cycle through a database table and populate checkbox option titles based on data from the database. This works perfectly.

For example:

   <?php foreach ($bud_items_si as $check_si => $label_text) : ?>

<?php $data_si = array(
            'name' => $check_si,
            'id' => $check_si,
            'value' => $check_si,
            'class' => '',                      
        );   

        echo '<div class="checkbox">';

        echo form_label(form_checkbox($data_si) . $label_text->bud_item, $check_si.'-label', array('for' => $check_si));

        echo '</div>';
    endforeach;

The problem is that I don't know how to identify each individual checkbox for the validation file. Typically to pass the checkbox values to the validation file it would look something like this:

$this->form_validation->set_rules('sit_nm', 'Site Name', 'required');

Any ideas on how to get the individual checkbox name values from the array to pass to the validator?

If all the check box are independent you should use a different name for each one! If they are related you should try using an array <input type="checkbox" name="name[]" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM