I have this form (I used crud generator and model generator):
Create Pig
[Name]
[Breed]
[Sickness] [Add sickness]
How do I make add sickness create a new textfield everytime I click it? I already have a table for the multivalued sicknessid, I just need to access that table and add all the sicknesses, use one same id so I can use it as foreign key in the table.
<?php
/* @var $this PigController */
/* @var $model Pig */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'pig-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->dropDownList($model,'name');?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'breed'); ?>
<?php echo $form->dropDownList($model,'breed', $model- >getBreedOptions()); ?>
<?php echo $form->error($model,'breed'); ?>
</div>
/*
ENTER CODE FOR SICKNESS HERE
*/
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
I also had the same scenario. What i have done is with script.
Try this. It worked for me. Please do make necessary changes