Define variable

When I define variable like this

$hello = $_POST[‘hello’];

I got this error

PHP Error

Description

Undefined index: hello

$hello = $_POST[‘hello’];

my actionController

public function actionTest()

{


	$model=new HelloForm;


	


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


	{


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


		$hello = $_POST['hello'];


		if($model->validate())


			$this->redirect(array('index'));


	}


	$this->renderPartial('test',array('model'=>$model));


}

}

Can anyone tell me how to define my variable?

Typo . When I define variable like this

$hello = $_POST[‘hello’];

I got this error

PHP Error

Description

Undefined index: hello

$hello = $_POST[‘hello’];

my actionController

public function actionTest()

{

$model=new HelloForm;

if(isset($_POST[‘HelloForm’]))

{

$model->attributes=$_POST[‘HelloForm’];

$hello = $_POST[‘hello’];

if($model->validate())

$this->redirect(array(‘index’));

}

$this->renderPartial(‘test’,array(‘model’=>$model));

}

}

Can anyone tell me how to define my variable?

Hi Archi

I admire your pluck, diving in at the deep end, but a lot of the questions you are asking are very basic PHP questions which can be solved with some research on the internet. I wonder if you might be in a little over your head with going straight into Yii without a grounding in simpler PHP.

You can always put a print_r() in your code to print out the $_POST array and see what the form is sending to the server. Just put this at the top of the action in your controller.




print_r($_POST);



I suspect your problem is that you might need to use $_POST[‘HelloForm’][‘hello’] instead of $_POST[‘hello’].