how to set required field validator for tabular input in yii

Anyone can teach me how to set required validator for tabular input? anything to do with the MODEL?

<?php foreach($questions as $i=>$question){ ?>



			<td style='width:150px;border:1px solid black'><?php echo $form->radioButtonList($model,"[$i]evaluation_mark",array('0'=>'0','1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5'),array('separator' => " | ", 'labelOptions'=>array('style'=>'display:inline')));?></td>

			<?php //echo $form->error($model,"[$i]evaluation_mark"); ?>

			<td style='width:150px;border:1px solid black'><?php echo $form->textField($model,"[$i]evaluation_comment"); ?></td>

			<?php echo $form->hiddenField($model,"[$i]evaluation_questionID",array('value'=>$i+1)); ?>

			<?php echo $form->hiddenField($model,"[$i]evaluation_userID",array('value'=>$userID)); ?>

			<?php echo $form->hiddenField($model,"[$i]evaluation_startdate",array('value'=>$startdate));?>

			<?php echo $form->hiddenField($model,"[$i]evaluation_enddate",array('value'=>$enddate));?>			


		<?php }?>

I want to set required validator for all the evaluation_mark. But how??

check first guide in "Collecting Tabular Input"

Thanks R.K.

But what does "If there are any validation errors, the corresponding input fields will be highlighted automatically, just like the single model input we described earlier on." mean?

in my Evaluation.php(model) should i put



foreach($questions as $i=>$question){array("[$i]evaluation_mark",'required'),}

A validator is always tied to a model so in your case you would use


In fact it is exactly the same thing as if you would use a single model. If you validate a model and validation fails you can get the errors by calling $model->getErrors(). So this part:

<?php echo $form->error($model,"[$i]evaluation_mark"); ?>

will get filled with the error message

Hi Haensel.Is it correct with what i done as below?

><?php echo $form->radioButtonList($model,"[$i]evaluation_mark",array('0'=>'0','1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5'),array('separator' => " | ", 'labelOptions'=>array('style'=>'display:inline')));?>

                        <?php echo $form->error($model,"[$i]evaluation_mark"); ?> // I am not sure about this as after i create 'save; button it didn't save anything if i leave the radiobutton blank but it also doesn't show any warning message

Yes, the syntax seems fine. Maybe there is a problem with the array filled with the models? Try printing the errors array with


to see if it is empty