Yii Framework Forum: How To Add File Upload Dynamically? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Add File Upload Dynamically? Rate Topic: -----

#1 User is offline   Shobhith C 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 10-January 13
  • Location:Cochin

Posted 12 January 2013 - 04:10 AM

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?
0

#2 User is offline   Nisanth thulasi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 62
  • Joined: 10-July 12
  • Location:Kochi

Posted 12 January 2013 - 05:33 AM

View PostShobhith C, on 12 January 2013 - 04:10 AM, said:

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
Thanks
Nisanth Thulasi
0

#3 User is offline   Shobhith C 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 10-January 13
  • Location:Cochin

Posted 12 January 2013 - 07:25 AM

View PostNisanth thulasi, on 12 January 2013 - 05:33 AM, said:

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?
0

#4 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 730
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 12 January 2013 - 03:13 PM

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>



https://gist.github.com/4520267


I tested the code its working
0

#5 User is offline   Shobhith C 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 10-January 13
  • Location:Cochin

Posted 14 January 2013 - 01:20 AM

View Postalirz23, on 12 January 2013 - 03:13 PM, said:

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>



https://gist.github.com/4520267


I tested the code its working



Thanks :)
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users