How To Add File Upload Dynamically?


i have created a form using Gii.when i click ‘add more’ link i want to add a new file feild to upload a file.How i can add file feilds dynamically to my form?


please refer this link dynamic fields adding

Thank you for the link.

now i can add extra filefeild.But how i can remove extra added one if needed?

this is fairly simple task if you have basic understanding of javascript/jQuery you can achieve this with few lines of code here is a example i whipped up in 5 minutes

<?php echo CHtml::link("add new item", "#", array('id'=>'add-new-item')); ?>


<?php echo CHtml::link("remove item", "#", array('id'=>'remove-item')); ?>



<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

<script type="text/javascript">



		var str='';

		str += '<div><?php echo CHtml::textField("FieldName"); ?></div>';





		$('#form > div').last().remove();





<form id="form">


I tested the code its working

Thanks :)