I'm adding dinamically textfields to a property in the model called names, but I like to set validation rules to every name in the array names in the view, Is this possible to do it unsing validation rules in the CForm Model?, for example I like to validate that every name will be required after clicking the Button.
This is the code of the view with a CActiveForm
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'test',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<p class="note">Campos <span class="required">*</span> son obligatorios.</p>
<div class="row">
<?php echo $form->labelEx($model,'Age'); ?>
<?php echo $form->textField($model,'age'); ?>
<?php echo $form->error($model,'age'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Name'); ?>
<?php echo $form->passwordField($model,'names[0]'); ?>
<?php echo $form->error($model,'names[0]'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Name'); ?>
<?php echo $form->passwordField($model,'names[1]'); ?>
<?php echo $form->error($model,'names[1]'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('test'); ?>
</div>
<?php $this->endWidget(); ?>
First you need to specify the relation within the model.Like:
Then in the search function use that relation like:
And use that in your view like: