1
votes

I have a page that contains a form in my Yii app.

I want to allow all users to view this form, but on submission of the form, if the user is not logged in - I want to redirect him to the login page. After the user logs in, I want to continue the original form submission.

For example in this page : http://www.yiiframework.com/demos/blog/index.php/post/13/sadfasdfasdf#comments When the user clicks on "submit" he will be redirected to the login page and after login his comment will be submitted has a logged in user.

How should I do that?


The solution I used :

  1. I followed this info to set the return URL : http://www.yiiframework.com/wiki/43/adding-login-form-to-each-page/

  2. Before sending the guest to the login page, I save the POST info in session. Than when the user gets redirected to the original page, I check if the session contains the original POST info and if it does - I save it with the new user id

3

3 Answers

1
votes

You will need to store the original POST variables in session if the user isn't logged in. Otherwise, event if you use the returnUrl as other folks are suggesting, you will have lost the comment originally submitted.

2
votes

You should use:

$this->redirect(Yii::app()->user->returnUrl);

This will redirect on a page that has requested user for authorization.

0
votes

by using url referrer you can do this stuff

$returnUrl = Yii::app()->request->urlReferrer;