Hi
I am trying to post a variable from a view/textfield to controller. I am unable to do so. Below is the code for controller and view. I have highlighted what is not working.
View code
<div class="form">
<?php echo CHtml::beginForm()?>
<?php echo CHtml::activeLabel($model2, "username")?>
<?php echo CHtml::activeLabel($model2, "email")?>
[b]<?php echo CHtml::activeTextField($model2, “email”,array(‘id’=>‘foo’))?>
[/b]
<ul class="tasks">
<?php /*?><?php $this->renderPartial('_task', array('model' => $model2));?><?php */?>
</ul>
<div class="row buttons">
<?php echo CHtml::button('Add Player',array('class' => 'tasks-add'))?>
<?php Yii::app()->clientScript->registerCoreScript
("jquery")?>
<script>
$(".tasks-add").click(function(){
$.ajax({
success: function(html){
$(".tasks").append(html);
},
type: 'get',
url: '<?php echo $this->createUrl('field')?>',
[b] data: {
index:$("#foo").val()[/b]
},
cache: false,
dataType: 'html'
});
});
</script>
</div>
<?php echo CHtml::endForm()?>
Controller code
class HomeController extends Controller
{
public function filters()
{
return array(
'ajaxOnly + field'
);
}
public function actionIndex()
{
$model= new Teamname;
$model1= new Gametype;
$select = array();
$model1 = Gametype::model()->findAll();
$model2 = new User();
$this->render('createteam', array('model'=>$model,'model1'=>$model1,'model'=>$model, 'model2'=>$model2, 'select'=>$select));
}
[b]public function actionField($index)
{
if(isset($_POST['index']))
{
$model2 = new User();
$this->renderPartial('_task', array('model' => $model2));
}
}
}
[/b]