0
<?php 
$options = array(
 'infant'  => '1',
 'mater'    => '2',
 'prees'   => '3',
 'kinder' => '4', );

echo form_open('evals/proc_group'); 
echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels)); echo form_label ('Infantes', 'infant',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','2', in_array('2', $educational_levels)); echo form_label ('Maternales', 'mater',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','3', in_array('3', $educational_levels)); echo form_label ('Preescolares', 'prees',  array ('class' => 'checkbox_label'));
echo form_checkbox('edu_level[]','4', in_array('4', $educational_levels)); echo form_label ('Kindergarten', 'kinder',  array ('class' => 'checkbox_label')); ?>

<input type="hidden" name="eval_id" value="<?php echo $evaluation->id ?>" />                                   
<div class="clear"></div>                                       
<?php echo form_submit('mysubmit','Guardar Grupo'); ?> 
<div class="clear"></div>
<?php echo form_close(); ?>
<div class="clear"></div>

当我按下 Guardar Grupo 时,我需要复选框保持选中状态。我能做些什么?

4

2 回答 2

0

执行 aprint_r($educational_levels)查看数组是否包含值。除此之外,我看不出有什么不寻常的。还要确保这$educational_levels是一个单维数组。
这对我来说非常有效:

public function index()
{
    //$this->load->view('welcome_message');
    $this->load->helper('form');
    $educational_levels = array('1', '3');
    echo form_checkbox('edu_level[]','1', in_array('1', $educational_levels));
}

您需要检查您的数组$educational_levels contains values和是否为not empty!.

于 2013-11-06T13:12:54.730 回答
0

希望这会奏效,我自己还没有检查过代码。

var checkboxes = $('.checkbox_label');
for ( i = 0 ; i < checkboxes.length; i++ ) {
    checkboxes[i].prop('checked', true)
}

您必须将此添加到表单的提交按钮单击事件中。

于 2013-11-06T13:00:05.767 回答