How To Add File Upload Dynamically?

hi,

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?

Hi

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')); ?>

&nbsp;

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

 

 

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

<script type="text/javascript">

$('document').ready(function(){

21$('a#add-new-item').click(function(){

		var str='';

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

		$('#form').append(str);

	});

 

	$('a#remove-item').click(function(){

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

	});

});

</script>

 

<form id="form">

</form>



I tested the code its working

Thanks :)