Hi guys good day, I want to ask something. I have here a autocomplete textfield where I type the employee id but when i save it using actionCreate it always insert an integer 1 value. This is my codes I hope someone can help me with this.
public function actionCreate()
{
$model=new ShisConsultation;
$timezone = "Asia/Manila";
if(function_exists('date_default_timezone_set'))
{
date_default_timezone_set($timezone);
$date = date('Y-m-d h:i:s A');
$date2 = date('Y-m-d');
}
$row = Yii::app()->db->createCommand(array(
'select' => array('*'),
'from' => 'shis_duty',
'where' => 'duty_date=:date2',
'params' => array(':date2'=>$date2),
))->queryRow();
$dr = $row['duty_fullname'];
$dr_re = $row['duty_reliever'];
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['ShisConsultation']['cons_type']))
{
if($_POST['ShisConsultation']['cons_type'] == 1)
{
if(isset($_POST['ShisConsultation']))
{
$model->attributes=$_POST['ShisConsultation'];
$model->cons_user_id = Yii::app()->user->getState('userid');
$model->cons_date_time = $date;
$model->cons_comment = $_POST['ShisConsultation']['cons_comment'];
$model->cons_type = "Guest";
if($dr_re == null)
{
$model->fk_duty = $dr;
}
else
{
$model->fk_duty = $dr_re;
}
if($model->save())
$this->redirect(array('view','id'=>$model->cons_id));
}
}
else
{
if(isset($_POST['ShisConsultation']))
{
$model->attributes=$_POST['ShisConsultation'];
$model->cons_user_id = Yii::app()->user->getState('userid');
$model->cons_date_time = $date;
$model->cons_cm_id = isset($_POST['cons_cm_id']);
$model->cons_comment = $_POST['ShisConsultation']['cons_comment'];
$model->cons_type = "Cast Member";
if($dr_re == null)
{
$model->fk_duty = $dr;
}
else
{
$model->fk_duty = $dr_re;
}
if($model->save())
$this->redirect(array('view','id'=>$model->cons_id));
}
}
}
$this->render('create',array(
'model'=>$model,
));
}
this is my form
<?php
$form->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'cons_cm_id',
'source'=>$this->createUrl('shisConsultation/autocompleteTest'),
'options'=>array(
'showAnim'=>'fold',
),
));
?>
and this is my autocompleteAction
public function actionAutocompleteTest() {
$res =array();
if (isset($_GET['term'])) {
// http://www.yiiframework.com/doc/guide/database.dao
$qtxt ="SELECT cm_id FROM shis_cm WHERE cm_id LIKE :cm_id";
$command =Yii::app()->db->createCommand($qtxt);
$command->bindValue(":cm_id", $_GET['term'].'%', PDO::PARAM_INT);
$res =$command->queryColumn();
}
echo CJSON::encode($res);
Yii::app()->end();
}