public function actionCreate()
{
$model=new Fruits;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Fruits']))
{
$model->attributes=$_POST['Fruits'];
echo $model->Fruits;
}
$this->render('create',array(
'model'=>$model,
));
}
The echo value of $model->Fruits always return 0 even if i select Orange.
Alright, thought $model->attributes=$_POST[‘Fruits’] will assign values into the model
I notice there is a strange effect on the dropdownlist if there is validation errors like required field not filled in. Say i select Orange then click submit, a validation error return due to one of the required field not filled in. I would expect the selected value of Orange is preserved but it changed back to Apple!?
Other text field values were preserved properly but dropdown were not. How do i make dropdown preserve previous values when validation error?