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?
Page 1 of 1
How To Add File Upload Dynamically?
#2
Posted 12 January 2013 - 05:33 AM
Shobhith 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?
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
Nisanth Thulasi
#3
Posted 12 January 2013 - 07:25 AM
#4
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
https://gist.github.com/4520267
I tested the code its working
<?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">
$('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
#5
Posted 14 January 2013 - 01:20 AM
alirz23, 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
https://gist.github.com/4520267
I tested the code its working
<?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">
$('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
Share this topic:
Page 1 of 1

Help












