save fields as arrays

hi all…

I have a textFeild in a loop.say the loop runs 5 times i get that textField % times. i want to populate all the 5 textFeilds and then save in the database. to do so i converted the textField into an array. but then it gives me following error:

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

need some help


You cannot validate as string an array.

You should collect the data as an array, then validate each string and serlize only before save (after validation).

Anyway a better approach is to create a separate table and then collect the input as tabular.

This is ma code in the form:


$sql="SELECT p.product_name, bp.quantity FROM bus_products as bp inner join products as p on p.product_id=bp.product_id WHERE bus_type_id='$bus_type_id'";


// bind the 1st column (username) with the $username variable


// bind the 2nd column (email) with the $email variable



<table width="100%" border="1" cellspacing="0" cellpadding="0">

  <tr><td><?php echo $form->labelEx($model,'issue_date'); ?></td>

    <td><?php echo $form->labelEx($model,'product_issued'); ?></td>

    <td><?php echo $form->labelEx($model,'Quantity allowed'); ?></td>

    <td><?php echo $form->labelEx($model,'quantity_left'); ?></td>

     <td><?php echo $form->labelEx($model,'quantity_isued'); ?></td>

     <td><?php // echo $form->labelEx($model,'extra_product'); ?></td>

     <td><?php echo $form->labelEx($model,'extra_quantity'); ?></td>







     <tr><td><? echo $form->textField($model,'issue_date[]',array('size'=>10,'maxlength'=>255,'value'=>date("d-m-Y"))); ?> </td>

        <td><?php echo $form->textField($model,'product_issued[]',array('size'=>10,'maxlength'=>255,'value'=> $product_name)); ?></td>

        <td><? echo $quantity;?></td>

        <td><?php echo $form->textField($model,'quantity_left[]',array('size'=>10,'maxlength'=>255,'value'=> $quantity)); ?></td>

        <td><?php echo $form->textField($model,'quantity_isued'.$i,array('size'=>10,'maxlength'=>255)); ?></td>

                <td><?php echo $form->textField($model,'extra_quantity[]',array('size'=>10,'maxlength'=>255)); ?></td>








What changes do i make??

That’s not the yii approach, you should restart in a more standard way.

Take a look at this extension, maybe it can solve your problem.

Also consider that collecting tabular input is a quite advanced task, not easy at all even for skilled users.

hi mithila,

i was trying to select multiple values in a checkboxlist and i got it as this. May be this can help you.

first collect all the values in an array and then assign the array to the model object.

	$model=new Flatchargesmapping;

        $chargecode= array();

        $modelcharge = new Flatchargesmapping;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);




			$chargecode = $modelcharge->Charge_code;

                        $flag= "false";

                        for ($i=0;$i<count($chargecode);$i++)


         				$model=new Flatchargesmapping;

         		                 $model->flat_number = $modelcharge->flat_number;

		          		 $model->Charge_code = $chargecode[$i];





				  if (!$model->save()) {

  								 	 echo "didn't work";

								     Yii::app()->end(); // don't use die();