Make validation rules for dynamic form

hello guys, i have form with dynamic text field i can add and remove text field in that form. But i have problem, i want to make rules validation for every textfield in that form. Do you have answer for my problem ?


<?php Yii::app()->clientScript->registerScript('textFieldAdder','$("#additional-link").bind("click",function(){

    var id="optional_text";

    var size=$("#additional-inputs > li input").size();

    $("#additional-inputs").append("<li><input type=text id="+id+size+" name="+id+"["+size+"]></li>");


<?php $form = $this->beginWidget('CActiveForm', array(



)); ?>

<?php echo CHtml::link('Add input','#',array('id'=>'additional-link')); ?>


<div id="additional-inputs">

    <li><?php echo CHtml::textfield('optional_text[0]','');?></li>



<?php echo CHtml::submitButton('Submit');?>

<?php $this->endWidget('CActiveForm');?>

copy from haensel

Will this tutorial help you? You may need to add error message part under textfield.