3 of 4
3
AJAX Login Form…
Posted: 12 March 2008 03:11 PM   [ Ignore ]   [ # 37 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  209
Joined  03-01-2006

I am also looking for a solution to this issue.

Cocoa, if you wouldn’t mind PM’ing me any info that you have as a starting point that would be great.

Cheers!

Profile
 
 
Posted: 03 May 2008 05:15 AM   [ Ignore ]   [ # 38 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  10-25-2007

Coming from a jQuery point of view (love this framework!), this is the concept behind the functionality you want:

Create the ‘normal’ EE login form. Using the id of the form, use the jQuery Form Plugin (http://www.malsup.com/jquery/form/) to “ajaxify” the form.

With this plugin you can define what element in the DOM should be updated with the form’s submission result (which will be some kind of template) and voila, done.

E.g.
Assuming that the form as the id ‘login’ (I haven’t used the exact value eludes me) and the div you want the message to appear has id=“login-div”, the code for changing the standard form to Ajax would be:

var options = {target : "#login-div"};

$(
document.ready(function()
{
  
$("#login").ajaxForm(options);
}

(don’t forget that you have to load jquery and the plugin in your html head section before the code, though).

This should (theoretical! I haven’t tried it out) make a the login form Ajax-style without hacking too much smile Check the website of the jQuery form Plugin for more options and details. If you have any problems you can always contact me. If we have created a final, workig version of this, we’ll put it into the knowledge base.

Profile
 
 
Posted: 03 May 2008 05:30 AM   [ Ignore ]   [ # 39 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

Hi juro,

WOW. Had seen that jQuery form plugin before but never even thought about doing that with it! Had actually all but forgotten about this thread. Just gave it a go and it worked first time! Simple and absolutely elegant. I had to copy paste the login form tag from a rendered page so that I could add in an id=”“ attribute to the form but once I had done that it was absolutely plain sailing.

Thanks for pointing that one out. Any ideas though how you could make it use the name=”“ parameter in the script instead of requiring an id though as I don’t think (I could be wrong on this though) the login-form tag allows for an id parameter.

Thanks again for reminding me of that plugin. This is going to make many things a whole heap more interesting now!! wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 03 May 2008 05:40 AM   [ Ignore ]   [ # 40 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  10-25-2007

Using the ‘name’ attribute: no problem!

You can select the form by anything you feel like realy:

$(”#by-id”).ajaxForm() ... by id
$(”.by-class”).ajaxForm() ... by id
$(“form”).ajaxForm() ... all forms
$(“div#login-form form”).ajaxForm() ... all forms inside the div with id login-form

Specifically for your question (assuming the name is my-form)

$(“form[name=‘my-form’]”).ajaxForm()

should do the trick. See http://docs.jquery.com/Selectors/attributeEquals#attributevalue for more information.

You might want to look at selectors in jQuery: http://docs.jquery.com/Selectors .

Profile
 
 
Posted: 03 May 2008 05:50 AM   [ Ignore ]   [ # 41 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

EDIT - Hi Juro. Just to say that code worked great thanks. I did have to delete the single quotation marks and place them back in again as I think the forums may have put the wrong ones in there or something?

Hi Juro,

Thanks for the information there. I thought it would be possible but just thought I would put your obviously very knowledgeable mind to work for me!! wink

Will look into the documentation links you have provided there though so thanks for that. jQuery is still pretty new to me so still trying to wrap my head around how to do what I want.

Thanks again for the reminder of that plugin as it just works like a dream and is a dead cinch to set up wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 03 May 2008 06:32 AM   [ Ignore ]   [ # 42 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  10-25-2007

Glad I could be of assistance!

Profile
 
 
Posted: 03 May 2008 06:33 AM   [ Ignore ]   [ # 43 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

You most definitely have been, kind sir! wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 13 May 2008 03:30 AM   [ Ignore ]   [ # 44 ]  
Summer Student
Avatar
Total Posts:  9
Joined  01-21-2008

This thread looks like it concluded in the way I also want to implement logins on a site I am working on.

Mark, if you have time could you post how you implemented this into your EE site, it looks quite elegant!

Profile
 
 
Posted: 13 May 2008 04:02 AM   [ Ignore ]   [ # 45 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

Hiya,

Yep all I did was the following :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title></title>
<
style type="text/css">
<!--
*
{
    margin
: 0;
    
padding: 0;
}

html {
    font
-size: 62.5%;
}

body {
    color
: #666666;
    
font-size: 1.2em;
    
font-family: Arial, "Lucida Grande", Verdana, sans-serif, Helvetica;
    
margin: 0;
    
padding: 0;
    
text-align:center;
}

#wrapper {
    
margin: 0 auto;
    
width: 950px;
    
text-align:left;
}

a {
    text
-decoration: none;
}

a
:hover {
    text
-decoration: underline;
}
-->
</
style>
<
sc*ipt type="text/javasc*ipt" src="jquery-1.2.3.js"></sc*ipt>
<
sc*ipt type="text/javasc*ipt" src="jquery.form.js"></sc*ipt>
<
sc*ipt type="text/javasc*ipt">
    
// wait for the DOM to be loaded

    
$j(document).ready(function() {
        
// bind 'myForm' and provide a simple callback function
        
$j("#ajax-login-form").ajaxForm(function() {
        ale
*t("Thank you for your logging in!");
    
});
});
</
sc*ipt>
</
head>
<
body>

<
div id="wrapper">

{exp:member:login_form return="site/index" id="ajax-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 class='checkbox' type='checkbox' name='anon' value='1' checked='checked' /> Show my name in the online users list</p>
<
p><input type="submit" name="submit" value="Submit" /></p>
<
p><a href="{path=member/forgot_password}">Forgot your password?</a></p>
{/exp:member:login_form}

</div>
</
body>
</
html>

You’ll need to replace the * symbols in the code above with the letter r as the forum is stripping them out due to code insertion

You’ll need to download the Form Plugin for jQuery from here jQuery itself and you should hopefully be set. That is all from memory so if it doesn’t work just let me know and I will look at it some more and post the correct code if I have made any mistakes.

 

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 13 May 2008 04:44 AM   [ Ignore ]   [ # 46 ]  
Moderator
Avatar
RankRankRankRank
Total Posts:  1576
Joined  01-07-2008

If you’ll allow me to drop in on your example real quick.  It’s jQuery or $, instead of j$ (unless you make it so - see below)

(function($) {

// All content goes here

})(jQuery);


That closure will make sure that you can use $ (or j$ if you change the argument) and not have to worry about collisions.

Other than that, it looks excellent.

 Signature 
Profile
 
 
Posted: 13 May 2008 04:51 AM   [ Ignore ]   [ # 47 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

Hiya,

Oops sorry! As I said that was written by memory. The reason I had that in there was that I had another script that wasn’t written in jQuery that was interfering with it so I had to place :

<sc*ipt type="text/javasc*ipt">
var
$j = jQuery.noConflict();
</
sc*ipt>

into my site to make them work together.

Sorry about that. Yes you can take out the j in the two places where it occurs above. Thanks for pointing that out inparo. As I said though that was all from memory wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 13 May 2008 07:00 AM   [ Ignore ]   [ # 48 ]  
Summer Student
Avatar
Total Posts:  9
Joined  01-21-2008

Marvellous, thanks people.  I’ll give this a bash in the next day (I have to move the site to another host in the next few days) or so and will post back just to confirm everything a-ok.

Thanks again for the prompt response(s)!  grin

Profile
 
 
Posted: 13 May 2008 07:30 AM   [ Ignore ]   [ # 49 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6563
Joined  04-15-2006

No problem. Let us know how it goes. At the moment all the code that I’ve posted above does is logs the person in and then brings up an alert box to say thanks for logging in but you could effectively do anything you want once they are logged-in.

You could flash up a div on the screen for a few seconds telling them they are now logged-in or you could re-direct them somewhere else or whatever you can code in Javascript really.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 19 May 2008 05:46 AM   [ Ignore ]   [ # 50 ]  
Summer Student
Avatar
Total Posts:  9
Joined  01-21-2008

Ok, so i’ve played around a bit with this and think I am just confusing myself now!

I used your example code (with corrections made!) Mark, and this will always trigger alert() regardless of whether the login is successful or not.

So, I put in some testing code to see if I could trap the response from the server:

<sc*ipt type="text/javasc*ipt">
    
// wait for the DOM to be loaded

$(document).ready(
function()
{
$('#ajax-login-form').ajaxForm(
{
  target
: '#vars',
  
success: function(responseText, statusText) { alert(statusText); }
}
);
});
</
sc*ipt>

and it would appear that I am always getting “success” as a result [statusText], regardless of whether the login failed or succeeded - although I have a sneeky feeling this is just echoing the “success:” part.  The [responseText] supplies the template code of success or failure.

I’m a bit new to jQuery and javascript although I have a feeling I will be picking this up very quickly out of necessity.  Am I missing something simple?

Could you have a check of your code and see what you did Mark?

Thanks!

Profile
 
 
Posted: 19 May 2008 05:52 AM   [ Ignore ]   [ # 51 ]  
Moderator
Avatar
RankRankRankRank
Total Posts:  1576
Joined  01-07-2008

An ajax ‘success’ is simply a response with a 200 status code.  Since a failed login still returns a valid http response, it always returns an “OK” status.  I can’t think of any non-php solutions to your problem right now, but I’ll play around with it.

 Signature 
Profile
 
 
Posted: 19 May 2008 05:56 AM   [ Ignore ]   [ # 52 ]  
Summer Student
Avatar
Total Posts:  9
Joined  01-21-2008

Ah right, it’s a status code.  I don’t mind some PHP solution if you have one wink

EDIT: A PHP solution to compliment the jQuery form and interpreting the results, not a complete PHP alternative to logging in!

Profile
 
 
Posted: 31 July 2008 03:06 AM   [ Ignore ]   [ # 53 ]  
Summer Student
Total Posts:  12
Joined  10-04-2007

Does anyone know if there is a plugin for this out in the ether?

Profile
 
 
Posted: 15 September 2008 05:14 PM   [ Ignore ]   [ # 54 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  173
Joined  03-07-2007

Cocoa, are you ready to release some ajax goodies? (mootools 1.2 is out some time grin ) I’m willing to look at some options and hackery to get better ajaxified login- and search- in-between-notices.

Profile
 
 
   
3 of 4
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64978 Total Logged-in Users: 30
Total Topics: 82017 Total Anonymous Users: 22
Total Replies: 440823 Total Guests: 190
Total Posts: 522840    
Members ( View Memberlist )