Multiplication In Crud

I created a table name Receipt with columns product, quantity, price, total.

I use crud. In my create new receipt I want the value of ‘total’ will come from the product of ‘quantity’ and ‘price’.

You don’t say whether you want in the form itself or just when the model is saved?

In the first case, you can do it with jQuery on change event of the ‘quantity’ and ‘price’ fields. In the second case, you have to set $model->total in your controller’s create method (after the setAttributes part), and in that case you may just remove ‘total’ from the model’s ‘safe’ array.

where is setAttributes part? in the controller? I want to do this when the model is saved. What I did is this

public function actionCreate()

{


	$model=new Receipt;





	// Uncomment the following line if AJAX validation is needed


	// $this->performAjaxValidation($model);





	if(isset($_POST['Receipt']))


	{


		$model->total=$_POST['price'] * $_POST['quantity'];


		$model->attributes=$_POST['receipt'];


		if($model->save())


			$this->redirect(array('view','id'=>$model->id));


	}





	$this->render('create',array(


		'model'=>$model,


	));


}

but this doesnt work

I realize my mistake this will work

$model->total = $_POST[‘Receipt’][‘quantity’] * $_POST[‘Receipt’][‘price’];