Is There A Way To Submit A Form To The Same Controller/action That Rendered The View Without A Model?

From examples I have seen the only way to submit a form back to the controller/action that rendered it is if you used a model in the view, for example:


public function actionLogin()

{

	$model=$this->loadModel($id);


	// Uncomment the following line if AJAX validation is needed

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


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

	{

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

		if($model->save())

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

	}


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

		'model'=>$model,

	));

}

but what if I have a custom controller/action and custom form that doesn’t have a model? How would I check if it was submitted? In the above example you can simply use


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

but that only works if you are using a model.

Thanks

How about just


if($_POST)

Yii’s scaffolding adds the model because the way the form is generated, submitting a form has nothing to with having a model or not (rather then for example validating/inserting data)

In frameworkless PHP app you can use:




<form action="xpto.php" method="post">

  Field1: <input type="text" name="field1">

  Field2: <input type="text" name="field2">

  <input type="submit">

</form>



Then on the xpto.php you could check if the request was a POST with the same maner as:


if($_POST){

  $field1 = $_POST['field1'];

  ...

}else{

  //handle other types of request

}



Regards,

SilverPT

Hello JonnyD, welcome to Yii Forum!

I think if you just want to create a custom form, you should use the CFormModel. Also if you just want to render a view, then you just need to pass the view name, e.g.




...

    $this->render('viewName');

...



You can also check the LoginForm.php that is created with the default Yii App.

Both approaches are helpful, thanks guys!