简体   繁体   English

从数据库填充的复选框数组中获取数据

[英]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[]" /> 如果它们相关,则应尝试使用数组<input type="checkbox" name="name[]" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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