Hi. I'm having a little confusion with the form example in the guide. It would seem that if the form has an error, the logic in the controller drops through to display the form (and error). Ok. It also seems if there are no errors, that (according to the comments) control is returned once again to the form.
So my question is, how do I get to the next place…the place one would go via the normal form action? or, in the case of a typical php page where the page processes its own form, the place one would go via a header command after processing the form? The example seems to keep me on the form page forever.
public function actionLogin()
{
$form=new LoginForm;
if(isset($_POST['LoginForm']))
{
// collects user input data
$form->attributes=$_POST['LoginForm'];
// validates user input and redirect to previous page if validated
if($form->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
// displays the login form
$this->render('login',array('user'=>$form));
}
As you can see if the form is correctly validated you redirect the user where you want
Well, I assume from the example (yes, same one) that I could put some another redirect in place of the one that’s there.
But the one that's there, and the comment for it, say that if the form validates, the user will be returned to the previous page. That's where I get lost. Is there something about the flow of Yii's implementation of MVC that would have me wanting to return the user to the page they just left if there are no errors?
Well, let' say you have a rule that says you can't do something if you aren't a logged in user.
If you try to do it there are 2 possibilities, error page or, if loginUrl is set, you go to the the login page where you can login and (that's what we are talking about here) be returned to the page you tried to open but weren't authorized (now you are)
Tha't the whole point of that
$this->redirect(Yii::app()->user->returnUrl);
but you can have what you want
i have
$this->redirect(array('list'));
on the create form of a guestbook for example
or
$this->controller->refresh();
In the form of a loginPortlet i show on every page (that a case of staying in the same page instead of the previous one)