Forums

Chronoforms login replace Joomla login

evano 14 Feb, 2012
Hi

I have a question about using Chronoforms login to replace the Joomla login

I have created a form that overrides the standard Joomla login, it all works pretty well..

However it does not show the login status of the user

I.e

the login form here -

http://test.whitehatit.net/index.php?option=com_content&view=article&id=194:login&catid=44:online-store

user - test
password - test

when the user name and password is entered, they are logged in successfully, as they now have access to the additional menus items under support which are only available to logged in users. However when you go to the login page again, instead of displaying the Joomla login confirmation, Hi Test and the log out button, it simply shows the login form again and you are able to add in the above details again...

I'm assuming I need to add some sort of action to the Joomla Login OnSuccess Event to display the login status and the log out button but am not sure which...

Would you mind giving me an idea of what to do here?

Many thanks

evano
andypooz 14 Feb, 2012
The Hi [Username] thing is usually displayed in a module that appears on the page whether the user is logged in or not- If they are logged in it displays the Greeting and logout options, if they aren't logged in, it displays the form. This way users have a way of logging out whenever they choose without having to click back to the login form in the component position.

What you want to do is to have an if statement that checks if anyone is logged in:

<?php
$user =& JFactory::getUser();
$uid = $user->get('id');


if the userid exists:

if ($uid>0) {


then display a message to them:

echo "Hi " . $user->get('name');


and the log out link:

<a href="index.php?option=com_user&task=logout&return=Lw">Log out</a>


otherwise display the form:

} else {

//add your existing form code here

}
?>


So, all together, what you'd do is replace the form HTML with this:

<?php
$user =& JFactory::getUser();
$uid = $user->get('id');
if ($uid>0) {
echo "Hi " . $user->get('name') . "<br/>";
<a href="index.php?option=com_user&task=logout&return=Lw">Log out</a>
} else {
?>

[[Original form code goes here]]

<?php
}
?>


Code isn't tested, but should work. If you put an event loop as the event OnSuccess then when the page is refreshed after login it should display the welcome message (Although you may prefer to just have them taken to the front page as appears to be the case now).

Bob, you may have a more elegant solution to this or maybe Chronoforms has some tricks built-in??

Andy
GreyHead 14 Feb, 2012
Hi Andy,

That how I'd thought of doing it when I read Evan's post. I've been scratching my head to see if there is a more elegant way to do it with ChronoForms without using Custom HTML and I'm not certain that there is without using multiple forms or JavaScript - and that seems like hard work.

Bob
Max_admin 14 Feb, 2012
Hello,

Well, You can use the new "Page Break" feature for this, in the "Preview", add your login form fields and button..etc, then add a "Page Break", then a "Custom Element" with the following code:


<?php
$user =& JFactory::getUser();
echo "Hi " . $user->get('name');
?>


Then a "Logout" submit button.

Now, under the "Events", add a "Custom server side validation" event, then enter this PHP code to check the user logged in status:

<?php
$user =& JFactory::getUser();
$return = ($user->get('id') > 0) ? true : false;
return $return;
?>


Then drag 2 "Show HTML" actions, one under the "on success" event and another under the "on fail" event, the one under the "on success" will have to be configured to "Show Page" = 2.

That should do it I think.

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
This topic is locked and no more replies can be posted.