1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Custom login form in fabrik

Discussion in 'Community' started by guzzyman, Oct 8, 2010.

  1. guzzyman

    guzzyman New Member

    Level: Community
    Hi guys, I want to create a custom login form using fabrika. Does anyone have any idea how that can be done? Or has anybody tried it out? Please kindly give me clues on how this can be done.

    Thanks,
    Guzzyman.
     
  2. railer

    railer Member

    Level: Community
    Hi Guzzyman,

    I know this post was from a while back, but I am wondering if you were able to build a custom login form and how you did it? Please let me know.

    Thanks,
    railer
     
  3. troester

    troester Well-Known Member Staff Member

    Level: Community
    Create a table with elements for name, username, password,.... (see the "Create Joomla user" form submission plugin) + additional elements you need.
    Add the "Create Joomla user" submission plugin to your form (see the tooltips for configuration details)
     
    1 person likes this.
  4. railer

    railer Member

    Level: Community
    Will this also work if for as a replacement for CB login? The main reason I need to do this is to redirect the logged in user to a specific CB Subs plan upgrade page.

    After some thought, what you were suggesting Troester, is creating a registration form, correct? But what I want is an alternate login form for CB which I can use to redirect pre-registered users to a CB Subs subscription upgrade form. I tried duplicating and modifying the CB Login module, but it doesn't seem to allow me to redirect users to the upgrade form. Because I duplicated it, it still reverts to the default CB Login form.

    Any ideas?

    Thanks,
    railer
     
  5. remico

    remico Member

    Level: Community
    I know this is an (very) old thread but I've made a Joomla login form with Fabrik if anybody is still interested...
     
  6. mansonul

    mansonul New Member

    Level: Community
    Hello remico,

    I'm interested!
     
  7. remico

    remico Member

    Level: Community
    I'll try to explain shortly how to make your own login form with Fabrik (skipping validation stuff etc.) I would really like to participate in a "tips and tricks" like wiki because I also have some other nice tricks with Fabrik...
    • Make a form (no need to connect it to a table) and place two field elements (username and password).
    • Make a PHP script (called it login_process.php) and upload it to /plugins/fabrik_form/php/scripts.
    • Add a PHP plug-in to the login form pointing to the script and run it on "onAfterProcess"
    • Make a menu item in Joomla that points to the login form. Alias "login" would be nice...
    • Make a override in your template for the Joomla login by making a copying components/com_users/views/login/tmpl/default_login.php to templates/[your-template]/html/com_users/login/default_login.php
    • Add This code to the top of default_login.php to redirect al login traffic to out Fabrik form:
    PHP:
    //redirect all traffic to fabrik login.
    $app = JFactory::getApplication();
    $link = '/login/?'.$_SERVER['QUERY_STRING'];
    $app->redirect($link, '', '');
    Place this code in the login_process.php php script:
    PHP:
    <?
    defined('_JEXEC') or die();
    jimport('joomla.user.helper');
     
    $db =&JFactory::getDBO();
    $lang =& JFactory::getLanguage();
    $app = & JFactory::getApplication();
     
    $credentials['username'] = $formModel->_formData['___username'];
    $credentials['password'] = $formModel->_formData['___password'];
         
    $sql= "SELECT id, password FROM #__users WHERE username='".$credentials['username']."'";
    $db->setQuery($sql);
    $result = $db->loadObject();
     
    if($result){
        $parts    = explode( ':', $result->password );
        $crypt    = $parts[0];
        $salt    = @$parts[1];
        $testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
     
        if ($crypt == $testcrypt) {
            $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
            $login = $app->login($credentials, $options);
        } else {
            $error = "Password incorrect";
        }
    }else{
        $error = "Username not found";
    }
     
    // start redirection
    // You can add ?redirect=[url] in the url to redirect after the login.
    if($login){
        if ($_REQUEST["redirect"]){
            $app->redirect('/'.$_REQUEST["redirect"].'/?'.$_SERVER['QUERY_STRING'],'Login successfull', 'message');
        }else{
            $app->redirect('/'.$_REQUEST["redirect"],'Login successfull', 'message');
        }
    }else{
        $app->redirect($_SERVER['REQUEST_URI'],$error, 'error');
    }
     
    exit;
    ?>
    To really make it complete, you can also insert a calc field with this code to make the forgot links.
    PHP:
    $lang =& JFactory::getLanguage();
    $lang->load('com_users',JPATH_ROOT);
    $return='';
    $return .= '<a href="'.JRoute::_('index.php?option=com_users&view=remind').'">';
    $return .= JText::_('COM_USERS_LOGIN_REMIND')."</a>";
    $return .= '<br>';
    $return .= '<a href="'.JRoute::_('index.php?option=com_users&view=reset').'">';
    $return .= JText::_('COM_USERS_LOGIN_RESET')."</a>";
    return $return;
    Hope this helps anyone to make their own login form. The real beauty of it is that you can run any script after a user logs in to the site!

    *** Forgot to mention. This is done with Fabrik 3 so in the wrong thread I think...
     
  8. troester

    troester Well-Known Member Staff Member

    Level: Community
  9. mansonul

    mansonul New Member

    Level: Community
    Hi troester,

    It is my bad, as I was searching all over the Fabrick's forum to find out how to make a login module to link to the registration form data from Fabrik.

    I use the juser plugin (for my registration form), but I don`t use the J! users table for storing the info. I have added a new database from Connections to store that data and I need a login form to look up in the other DB.

    P.S. I've "copied" the J! users columns and "pasted" in my new "demo_users" database.
     
  10. remico

    remico Member

    Level: Community
    Hi Troester,

    Can you make a login form only with the Juser form plugin? I couldn't do that. For the registration form I'm using the Juser plugin but that is kind of default I think...

    Can we move the "how to" for the Login form to another (Fabrik 3.x) thread or make a Wiki of it? I'm sure that there are more people lokking foor a Fabrik Login form...
     
  11. teoyh

    teoyh Member

    Level: Community
    I am looking to do a custom login form for Fabrik 3 and joomla 3.5 is this example here still applicable or is there any other example that someone can point me to. Many thanks
     
  12. remico

    remico Member

    Level: Community
    This should work for 3.5 (even less code...)
    PHP:

    defined('_JEXEC') or die();

    jimport('joomla.user.helper');
    $db =&JFactory::getDBO();
    $lang =& JFactory::getLanguage();
    $app = & JFactory::getApplication();

    $credentials['username'] = $formModel->formData['___username'];
    $credentials['password'] = $formModel->formData['___password'];

    if ($app->login($credentials)) {
        $msg="Login succesvol";
        $app->redirect('/yourr-url',$msg, 'success');
    }else{
        $msg="Login failed";
        $app->redirect('/yourr-url',$msg, 'error');
    }


     
     
    susannanam likes this.
  13. teoyh

    teoyh Member

    Level: Community
    Wow thank you so much, my jaw drop hahaha I tested it work like a charm cool man ....

    I noticed that I can leave the $msg blank joomla will throw the correct message
     
  14. remico

    remico Member

    Level: Community
    You're welcome! I asked for this to go in the howto wiki, because it's really nice and easy to use. In this way your able to set al kind of things after a login and use custom redirects. Really useful for many Fabrik users I think...
     
  15. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    It's a wiki. Feel free to add it. :)

    -- hugh
     
  16. teoyh

    teoyh Member

    Level: Community
    I have an issue here now that I am able to login, I try to redirect by putting the address I want to go but it does not seem to redirect to the page I want. It always go to the main page.

    May I know which file does it call when this command is issue $app->login($credentials). Is it from www\components\com_users\models\login.php or some other file ?
    if ($app->login($credentials)) {
    $msg="Login succesvol";
    $app->redirect('/yourr-url',$msg, 'success');
    }else{
    $msg="Login failed";
    $app->redirect('/yourr-url',$msg, 'error');
    }
     
  17. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I'm pretty sure login() does an explicit redirect, so probably your code is never reached. I think you can override it in the login module settings.

    -- hugh
     
  18. teoyh

    teoyh Member

    Level: Community
    I added the following code to this file in www\plugins\user\joomla\joomla.php.

    Inside the joomla.php there is a function call public function onUserLogin($user, $options = array()) ;
    I added the following to the above function, this will check my url for a return url if its present then it will assign to $options[return'] which will eventually be pass to the redirect in joomla.
    $return = JRequest::getVar('return',null);
    if($return!==''){
    $options['return']=$return;
    }

    Seriously I am not really sure what I am doing but it work somehow !!!
     
  19. remico

    remico Member

    Level: Community
    Hi Hugh,

    I tried it back then, but I didn't have access.... I'll try again.
     
  20. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    @teoyh - I really don't recommend that. Lots of reasons, including opening yourself (or rather your users) up to attacks. I'd recommend going to the joomla.org forums and asking how to do what you want to do without messing with J!'s core code.

    -- hugh
     

Share This Page