How To Change Forms Dynamically Based On Radiobutton Selection In Yii

I’m new to Yii framework and I’m designing a form (I’m using create form) to create a row in database.

Let me explain about the scenario succintly, so that I can make it clear for what I want-

I have 10 fields in this form. Out of this 10 fields, five fields change dynamically.

I created two div’s basically div A and div B and repeated the fields as required for the two cases.

Say some fields which are textfields in div A will be dropdownlists in div B.

<div id="A">

<?php echo $form->labelEx($model,'selectionList'); ?>

<?php echo $form->textArea($model,'selectionList',array('rows'=>6, 'cols'=>50)); ?>

<?php echo $form->error($model,'selectionList'); ?>


<div id="B">

<?php echo $form->labelEx($model,'selectionList'); ?>

<?php echo $form->dropdownList($model,'selectionList',array('rows'=>6, 'cols'=>50)); ?>

<?php echo $form->error($model,'selectionList'); ?>


I have two radiobuttons say Single and Multi. When I select Single radiobutton, div A should be considered and div B discarded and when I select Multi, vice versa should happen.

So, is this the right way to change the form fields dynamically. Or else how can I do this using Ajax validation.

This is not Yii specific.

Search the web for ‘jquery toggle div radiobutton’.

You will find for example:

Please use the below code

  1. call a ajax on radio button

<div class="row">


$form->radioButtonList($model, 'filed', array(0=>'Single',1=>'Multi'),





		'onclick' =>CHtml::ajax(array(










<div id="test"></div>

  1. In controller action

public function add(){

   $value =$_GET['test']


		//A div


		//B div




I hope it;s some help