Plugin

Developer
Supported

AJAX Login

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Laisvunas

     

You must be logged in to post.

Login Form Redirect

General

ppm
ppm

I have the login form on a seperate template page and instead of it just refreshing and saying “you are now logged in” is there a way where it can automatically direct to the “customer account” section i have created.

Laisvunas
# 1
Developer
Laisvunas

If I understood you correctly,you need to log-in using AJAX and just after logging-in you need to be redirected to customer account page?

ppm
# 2
ppm

Yes, however at the moment i cannot seem to redirect to the customer account page when logging in with AJAX.

Laisvunas
# 3
Developer
Laisvunas

Hi,

Create inside your template a simple javascript function

function my_redirect() {
location
.href="http://www.mysite.com/index.php/teplate_group/template/"

Then add “add_callback_login” parameter to your {exp:ajax_login} tag:

add_callback_login="my_redirect" 
ppm
# 4
ppm

Hi

I have tried copying what you said and I am still not being redirected . It logs in and says you are now logged in but stays on the login form template page instead of directing to the customer account.

I have posted my code below, I have been testing the redirect with google for now.

[removed][removed]

[removed]
function my_redirect() {
location
.href="http://www.google.com/"

[removed]

<div class="loginbg">
<
div class="loginheader">
<
div class="logocontainer clearfix">
<
div class="loginlogo"></div>
</
div>
</
div>

<
div class="loginbgshade"></div>


{exp:ajax_login add_callback_login="my_redirect" form_id="login_form" login_button_id="login_button" logout_button_id="logout_link" login_process_indicator_id="login_progress_indicator" login_process_indicator_class="process_indicator" logout_process_indicator_id="logout_progress_indicator" logout_process_indicator_class="process_indicator" error_message_container_id="login_error_indicator" error_message_container_class="login_error" success_message_container_id="login_success_indicator" success_message_container_class="login_success" hide_on_login="form_div|hello_guest" display_on_login="hello_user|logout_link" style_on_login_temporarily="login_success_indicator" style_on_login_temporarily_class="login_success"  style_on_logout_temporarily="login_success_indicator" style_on_logout_temporarily_class="login_success" hide_on_logout="hello_user" display_on_logout="hello_guest|form_div" username_id="username_el"}

<div id="hello_user" {if logged_out}style="display: none"{/if}>
<
h2>Hello <span id="username_el">{if logged_in}{username}{/if}</span></h2>
</
div>

<
div id="hello_guest" {if logged_in}style="display: none"{/if}>
<
h2>Hello Guest</h2>
</
div>

<
div id="login_error_indicator" class="hidden">
</
div>

<
div id="login_success_indicator" class="hidden">
</
div>

<
div id="login_progress_indicator" class="hidden">
Logging in...
</
div>

<
div id="logout_progress_indicator" class="hidden">
Logging out...
</
div>

<
div id="form_div" {if logged_in}style="display: none"{/if}>

{exp:member:login_form id="login_form"}

<p><label>Username</label><br />
<
input type="text" name="username" value="" maxlength="32" class="input" size="25" /></p>

<
p><label>Password</label><br />
<
input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>

{if auto_login}
<p><input class='checkbox' type='checkbox' name='auto_login' value='1' /> Auto-login on future visits</p>
{/if}

<p><input id="login_button" type="submit" name="submit" value="Submit" /></p>

{/exp:member:login_form}

</div>

<
a id="logout_link"style="display: none" href="{path='LOGOUT'}">Log out</a
Laisvunas
# 5
Developer
Laisvunas

Hi,

Check the demo here. It shows that my redirect code works.

Try to start from example template and add to it the code I suggested.

ppm
# 6
ppm

Hi

I have copied the example given in the following link http://devot-ee.com/add-ons/ajax-login/

I then added the redirect to the code however i am not being redirected anywhere.

I then copied the code from your demo provided and can see that the redirect is working there, however it only works using the username and password you provided. Is there a way to change it to my member usernames and passwords?

When I change the form to {exp:member:login_form id=“login_form”} and try to login as admin, i get an error message through the Ajax form stating the id number entered is incorrect.

Thanks

Laisvunas
# 7
Developer
Laisvunas

Hi,

Here is the code which works correctly in my example. 

<html>

<
head>

<
title>AJAX Login simple demo</title>

<
style>
div.process_indicator {
border
solid 1px green;
background-imageurl(http://www.mysite.com/images/ajax-loader.gif);
background-repeatno-repeat;
background-positioncenter;
height7em;
width20em;
text-aligncenter;
displayblock!important;
}

.hidden  {
display
none;
width20em;
}

div
.login_error {
color
red;
displayblock!important;
}

div
.login_success {
color
green;
backgroundyellow;
displayblock!important;
}
</style>

script type="text/javascript">
function 
my_redirect() {
location
.href="http://www.google.com";
}
< /script>

</
head>
<
body>

<
h1>AJAX Login simple demo</h1>


{exp:ajax_login form_id="login_form" login_button_id="login_button" logout_button_id="logout_link" login_process_indicator_id="login_progress_indicator" login_process_indicator_class="process_indicator" logout_process_indicator_id="logout_progress_indicator" logout_process_indicator_class="process_indicator" error_message_container_id="login_error_indicator" error_message_container_class="login_error" success_message_container_id="login_success_indicator" success_message_container_class="login_success" hide_on_login="form_div|hello_guest" display_on_login="hello_user|logout_link" style_on_login_temporarily="login_success_indicator" style_on_login_temporarily_class="login_success"  style_on_logout_temporarily="login_success_indicator" style_on_logout_temporarily_class="login_success" hide_on_logout="hello_user|logout_link" display_on_logout="hello_guest|form_div" username_id="username_el" add_callback_login="my_redirect"}

<div id="hello_user" {if logged_out}style="display: none"{/if}>
<
h2>Hello <span id="username_el">{if logged_in}{username}{/if}</span></h2>
</
div>

<
div id="hello_guest" {if logged_in}style="display: none"{/if}>
<
h2>Hello Guest</h2>
</
div>

<
div id="login_error_indicator" class="hidden">
</
div>

<
div id="login_success_indicator" class="hidden">
</
div>

<
div id="login_progress_indicator" class="hidden">
Logging in...
</
div>

<
div id="logout_progress_indicator" class="hidden">
Logging out...
</
div>

<
div id="form_div" {if logged_in}style="display: none"{/if}>

{exp:member:login_form id="login_form"}

<p><label>Username</label><br />
<
input type="text" name="username" value="" maxlength="32" class="input" size="25" /></p>

<
p><label>Password</label><br />
<
input type="password" name="password" value="" maxlength="32" class="input" size="25" /></p>

{if auto_login}
<p><input class='checkbox' type='checkbox' name='auto_login' value='1' /> Auto-login on future visits</p>
{/if}

<p><input id="login_button" type="submit" name="submit" value="Submit" /></p>

{/exp:member:login_form}

</div>

<
a id="logout_link"style="display: none" href="{path='LOGOUT'}">Log out</a>

</
body>
</
html