Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
本例中YII框架中任意一个的多个复选框有效性_Yii - Fatal编程技术网

本例中YII框架中任意一个的多个复选框有效性

本例中YII框架中任意一个的多个复选框有效性,yii,Yii,您好,您能告诉我如何验证yii框架中的多个复选框吗 数组('accept','required','requiredValue'=>1',message'=>'您应该选择alteast one')由于这些值通常作为数组发送,我曾经为这些情况编写了一个数组验证器: 用法示例: array('accept', 'ext.validators.P3ArrayValidator', 'min'=>1, 'allowEmpty'=>false, 'message' =>

您好,您能告诉我如何验证yii框架中的多个复选框吗


数组('accept','required','requiredValue'=>1',message'=>'您应该选择alteast one')

由于这些值通常作为数组发送,我曾经为这些情况编写了一个数组验证器:

用法示例:

array('accept',
  'ext.validators.P3ArrayValidator', 
  'min'=>1,
  'allowEmpty'=>false, 
  'message' => 'You should select at least one'
),

很抱歉迟了答复

但是,我找到了一个没有安装任何扩展的解决方案

获取一个同名的隐藏字段[复选框列表字段]

<?php echo $form->hiddenField($model,'categories');?>

验证复选框至少选中了一个复选框我必须验证多个复选框请大家帮助使用
CHTML::checkBoxList()
并使其成为必需的复选框对于此问题没有用处,请用示例告诉我仅验证checkboxhmm,我会说它完全符合您的需要,请参阅更新的使用示例。
<?php 
echo CHtml::checkBoxList(
    'group',
    //you can pass the array here which you want to be pre checked 
    explode(',', trim($model->attributes['categories'], ',')),
    CHtml::listData(Category::model()->findAll(),'id','name'),
    array('separator'=>'', 'template'=>'<tr><td style="width:5%;">{input}</td><td>{label}</td></tr>', 'class' => 'group')
);
?>
<script>
$(function(){
  $(".group").click(function(){
    var str = $('.group:checked').map(function() {
    return this.value;
    }).get().join();
    var groupCats = (str.length > 0) ? ','+str+',' : '';
    $('#ModelNAME_field').val(groupCats);
    // Get the 'ModelNAME_field' by viewing source of HTML of hidden field.
  });
});
</script>