Hey guys, i want ask something. I want to add an extra textField when i click button to my form. Please help me
Page 1 of 1
How to Add textfield in form when link is clicked
#2
Posted 16 September 2011 - 07:31 AM
A simple variant:
In your form view:
In your form view:
<?php Yii::app()->clientScript->registerScript('toggler','$("#optional-link").bind("click",function(){$("#optional-text").toggle();})')?>
<?php echo CHtml::link('Show/hide additional input','#',array('id'=>'optional-link')); ?>
<div id="optional-text">
<?php echo CHtml::textfield('optional_text','');?>
</div>
codecrumbs.at
My extensions:
ActiveResource for Yii - the RESTful equivalent to ActiveRecord | Neo4Yii - wrapper for the Neo4j graph database | EPhpThumb - a simple, lightweight wrapper for the phpThumb library
Get social:
Circle me on Google Plus
Follow me on Twitter
My extensions:
ActiveResource for Yii - the RESTful equivalent to ActiveRecord | Neo4Yii - wrapper for the Neo4j graph database | EPhpThumb - a simple, lightweight wrapper for the phpThumb library
Get social:
Circle me on Google Plus
Follow me on Twitter
#3
Posted 16 September 2011 - 07:39 AM
thanks but i want to add textfield, for example i have 1 textfield when i click button then i have 2 textfield. Can you help me please and i want it process like array
#4
Posted 16 September 2011 - 08:36 AM
Ok, but please be more specific next time 
If pure client side code fits your needs then here is an example (although very simple):
When submitting this form you will receive an array called optional_text with integer keys holding the values [0]=>firstvalue,[1]=>secondvalue. If you need a more complex solution using additonal models and stuff take a look at this wiki entry by zaccharia http://www.yiiframew...t-tabular-input
If pure client side code fits your needs then here is an example (although very simple):
<?php Yii::app()->clientScript->registerScript('textFieldAdder','$("#additional-link").bind("click",function(){
var id="optional_text";
var size=$("#additional-inputs > li input").size();
$("#additional-inputs").append("<li><input type=text id="+id+size+" name="+id+"["+size+"]></li>");
})')?>
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo CHtml::link('Add input','#',array('id'=>'additional-link')); ?>
<ul>
<div id="additional-inputs">
<li><?php echo CHtml::textfield('optional_text[0]','');?></li>
</div>
</ul>
<?php echo CHtml::submitButton('Submit');?>
<?php $this->endWidget('CActiveForm');?>
When submitting this form you will receive an array called optional_text with integer keys holding the values [0]=>firstvalue,[1]=>secondvalue. If you need a more complex solution using additonal models and stuff take a look at this wiki entry by zaccharia http://www.yiiframew...t-tabular-input
codecrumbs.at
My extensions:
ActiveResource for Yii - the RESTful equivalent to ActiveRecord | Neo4Yii - wrapper for the Neo4j graph database | EPhpThumb - a simple, lightweight wrapper for the phpThumb library
Get social:
Circle me on Google Plus
Follow me on Twitter
My extensions:
ActiveResource for Yii - the RESTful equivalent to ActiveRecord | Neo4Yii - wrapper for the Neo4j graph database | EPhpThumb - a simple, lightweight wrapper for the phpThumb library
Get social:
Circle me on Google Plus
Follow me on Twitter
#6
Posted 12 January 2013 - 07:33 AM
hi,
thanks.its very helpful for me.
how i can remove extra added one?
how i can remove extra added one?
Share this topic:
Page 1 of 1

Help












