How to preset values for forms

I’m using the gii generated code but i would like to preset some of the form values.

At a guess I should be setting the value in the controller but my attempts at doing this have so far failed.

So I have in the staffcontroller


	

public function actionCreate()

{

	$model=new Staff;


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

	{

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

		if($model->save())

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

	}

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

		'model'=>$model,

	));

}



the view makes use of the widget CActiveForm

I’m trying to preset a required value - companyid , and hide it from the user as they dont need to know about it.

So… you can set that after the attribute assignement like:




                ...

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

                $model->companyid=<your value>;

                if($model->save())

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

                ...



well that was simple - Thank you it works

and to disable the CActiveForm Validation on the companyid field was to remove companyid form the required rules array in the model.