Forums

Redirect user to same page

BNDragon 20 Nov, 2014
Hello,

I have two types of form:
Type 1: Register / Login to redereciona to a static URL
Type 2: Register and Login to access restricted pages with dynamic URL.

What I mean by dynamic is that when the user uses the form of type 2, it will be redirected to the same page where he was, which may vary greatly. For example, if the user wants to insert a news opens the "New News" menu and form type 2 arises after login the user must be redirected to the page of the "New News", the same case to pages of any type of data entry and even to view other user profiles.

The question is, how do I redirect the user to the current page?

Thanks in advance,
BN
GreyHead 20 Nov, 2014
Hi BN,

Get the current page URL and put it into a hidden input in the form, then use that to Redirect the user back again.

Please see this FAQ

Bob
BNDragon 21 Nov, 2014
Hi Bob,

That FAQ will help me, thanks, but I now realize a problem.
Like you know, I'm integrate HybridAuth with CF. The problem is that de HybridAuth have a return callback, the same that is in the social network, in my case is some like "mydomain.com/login", so, in this cases I need to rediret the user to login page and then to the page where he was.

I can't see an solution for this case.

Could you help me get to a solution?

Thanks,
BN
GreyHead 26 Nov, 2014
Hi BN,

I'm not sure without testing :-(

I think that there may be two ways to do it.

a) IIRC the Joomla! login has a redirect parameter so you may be able to set that when you call it.

or

b) You can use a ChronoForm for the login - that way you would have full control.

Bob
BNDragon 26 Nov, 2014
Hi Bob,

Can I call a action in php code?


The main problem is that the HybridAuth login is made in code, not on form.

BN
HerKle 28 Nov, 2014



Get the current page URL and put it into a hidden input in the form, then use that to Redirect the user back again.

…
Bob



Hi Bob,

how can I use a hidden input to redirect the user? I am missing the steps which seem obvious to both of you.

I got a similar problem from opening the form within an article with the plugin "Component anywhere".
The native CFv5 redirect utility as well as the chrono redirect external app do not function (by adding double slash resp. double directory within the path).

Kind regards,
Herbert
BNDragon 28 Nov, 2014
Hi Herbert,

To get the current url, you can use some like this
$url= JURI::current();

To set it in a field some like
$form->data["urlFieldName"]=$url

So, if you set a custom action before your HTML render with it all together, your field will be filled
<?php
    $url= JURI::current();
    $form->data["urlFieldName"]=$url;
?>


Now, what is left is to redirect the user, and that's the part that I still didn't get yet.
I was hopping to make a call of the redirect action on my code, but still no solution for it. 😟

Hope it helps you a little,
BN
BNDragon 09 Jan, 2015
Hi Bob,

Sorry to take back this old post, but I have a problem.
I solve the first problem with cookies, but a new one comes...

I'm redirect my user (in my tests I set the url to home page), but when it redirect my user, it goes to User Profile Page, first I thought that could be a CB configuration (the first login is redirect to User Profile Page) so I set the CB config in white (URL for authentication on the first visit = []), but the redirect still go to User Profile Page. :/

Hope I explained myself good.

Thanks,
BN
BNDragon 09 Jan, 2015
Hello,

I found the problem, a plug-in that redirects the users v.v
I deactivated it and it works, I now I found the real problem.

Well, the form is already submitted, so there is no form then

$form->data["currentPage"]=$url;

doesn't work, so my redirect looks like [code]http://mydomain.com/{currentPage}/code]

I tried some php, but the redirect action doesn't read the php [code]http://mydomain.com/<?php echo $url; ?> /code]

Help me here please.

BN
BNDragon 09 Jan, 2015
---------------------------------------------------------------------------------------------
[Sorry, no Edit, just adjust the tags]
---------------------------------------------------------------------------------------------
Hello,

I found the problem, a plug-in that redirects the users v.v

I deactivated it and it works, I now I found the real problem.

Well, the form is already submitted, so there is no form then

 $form->data["currentPage"]=$url;


doesn't work, so my redirect looks like
http://mydomain.com/{currentPage}


I tried some php, but the redirect action doesn't read the php
http://mydomain.com/<?php echo $url; ?> 


Help me here please.

BN
BNDragon 09 Jan, 2015
Answer
After new research i found this topic and Bob suggestion works like a charm.

So, What did I do? Quite simple actualy, I save the current url in a cookie the on submit, in my case on login, i load the cookie and make a redirect with the Bob's tip.
In a custom code before the Html Render I set:
<?php
$cookie_name = "current_url";
$cookie_value = JURI::current();;

if(!isset($_COOKIE[$cookie_name])) {
$time=time() + 3600;
setcookie($cookie_name, $cookie_value, $time, "/");
}  


And inside a custom code action inside the sucess of joomla login action
<?php
$cookie_name = "current_url";

if(isset($_COOKIE[$cookie_name])) {
$url= $_COOKIE[$cookie_name];
$time=time() - 3600;
 setcookie($cookie_name, false,$time , "/");
  $app =& JFactory::getApplication();
  $app->redirect($url);
}


The problem of this last part of code is that it doesn't remove the cookie. Why? No idea v.v
But its a working solution for me🙂

BN
This topic is locked and no more replies can be posted.