Checkbox transferring incorrect value to database

I have 2 tables, 1 of them holds information for the current "specials" running in the store. The other table is the list of services we offer.

the model names are Specials and Tsplus.

I am treating the Tsplus table as categories. Each row in the table is listed as a checkbox with it’s ID as the value. That value is then stored in the Specials table as a foreign ID.

<?php echo CHtml::activeCheckboxList(

	$model, 'tsPlus_id', 

	CHtml::listData($this->tsplusCatList(), 'id', 'name')

); ?>

The problem I am having is that when the form is submitted. Nothing is getting stored in the tsPlus_id column of the Specials table.

the HTML code being generated by the checkboxlist is this:

<input id="ytSpecials_tsPlus_id" type="hidden" value="" name="Specials[tsPlus_id]" />

<input id="Specials_tsPlus_id_0" value="1" type="checkbox" name="Specials[tsPlus_id][]" />

<label for="Specials_tsPlus_id_0">Screen Printing</label><br/> 

<input id="Specials_tsPlus_id_1" value="2" type="checkbox" name="Specials[tsPlus_id][]" />

<label for="Specials_tsPlus_id_1">Embroidery</label>

Does anyone have any ideas as to why this is happening? I don’t even know where to go from here on the debugging…

Hidden values should be set to ‘safe’ in your model validation rules. :)

Thank you, that allowed the value to be passed, however I was getting the "must be an integer" error. After checking the value being passed the code is trying to set the id as: Array.

I can’t figure out why it’s not passing the value even though the HTML code shows that the values are being set properly…

Here is how I have my validation set up:

public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

                array('title, listPoints', 'required'),

                array('title', 'length', 'max'=>250),

                array('tsPlus_id', 'safe'),

                array('id, tsPlus_id, signStop_id, title, listPoints', 'safe', 'on'=>'search'),



Again the code for the check boxes is:

<?php echo CHtml::activeCheckboxList(

        $model, 'tsPlus_id', 

        CHtml::listData($this->tsplusCatList(), 'id', 'name')

); ?>

and the tsplusCatList() function is:

public function tsplusCatList() {

        return Tsplus::model()->findAll();


Instead of passing the ID of the Tsplus object to the tsPlus_id field, its passing the string ‘Array’.

I can’t figure it out :confused: