checkBoxList

hello there,

i’ve been trying to use check boxes but am not finding it as straight forward as the drop down lists

i have a field in the DB called mv_stenosis which takes one or more of (ul,ml,ur). my view is as

 <div class="row">		


	<?php echo $form->labelEx($model,'mv_stenosis'); ?>				


	<?php echo $form->checkBoxList($model, 'mv_stenosis',array('ul'=>'ul','ml'=>'ml','ur'=>'ur')); ?>


	<?php echo $form->error($model,'mv_stenosis'); ?>		


</div>

i get the following PHP error on posting

mb_strlen() expects parameter 1 to be string, array given

Stack Trace

#0

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\yii\framework\validators\CStringValidator.php(72): mb_strlen(array("ul", "ml", "ur"), "UTF-8")

#1

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\yii\framework\validators\CValidator.php(192): CStringValidator->validateAttribute(Patient, "mv_stenosis")

#2

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\yii\framework\base\CModel.php(152): CValidator->validate(Patient, null)

#3

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\yii\framework\db\ar\CActiveRecord.php(778): CModel->validate(null)

what could i be missing here?

what validation rules have you set for "mv_stenosis" ?

i have removed the length validation rule, and the error went but the field is blank in the db.

i used print_r($_POST[‘ModelName’]); exit; in the controller and the values i get for that field is Array ( [0] => ul [1] => ml [2] => ur ) depending on the options checked.

i’ve also tried to print the values in the beforeSave() function but its blank

If you don’t have any validation rule… and use massive assignment… than this attribute is not assigned…

if no other validation is needed for this attribute… just set it as "safe"…

http://www.yiiframework.com/doc/guide/1.1/en/form.model#declaring-validation-rules