Untitled. Creative Agency Theme

Continue Reading
Mon. - Fri. 9 am - 5 pm Ask a Question
Remember me

Php script for adding user to joomla database

2 weeks 4 days ago #1

  • sen's Avatar
  • sen
  • Posts: 14
Hi,
I am creating a user registration form for new joomla user registration and adding new fields. I am wondering how i can add a user using Balbooa Forms into our joomla database, together with an administrator activation? Is there a ready php script i can use or modify from?
Is there any way to do this?

2 weeks 3 days ago #2

  • Vyacheslav's Avatar
  • Vyacheslav
  • Posts: 10581
Hello,
Thank you for contacting us

Unfortunately, this is not possible

Best Regards,
Vyacheslav, Balbooa Support Team

2 weeks 3 days ago #3

  • sen's Avatar
  • sen
  • Posts: 14
Actually, it is possible. We just need the right php script calls. I did some investigation and for those who need this function into Balbooa's beautiful forms, you can modify the script below: (if you need to setup user activation by admin, its possible too, but the script below is for basic user insertion to joomla user db)

----
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$app = JFactory::getApplication('site');
$app->initialise();

/* you may want to change this*/
$params = array(
    'name'=>'test',
    'username'=>'test_user',
    'email'=>'mail@example.com',
    'password'=>'test',

);

$udata = array(
    'name'=>$params['name'],
    'username'=>$params['username'],
    'password'=>$params['password'],
    'email'=>$params['email'],
    'groups'=>array(2), // set the usergroup(s) here (id)

);

$user = new JUser;

try{
    echo '<pre>';
    echo 'Bind user data: ';
    var_dump($user->bind($udata));         

    echo 'Save user data: ';
    var_dump($user->save());

    echo 'Testing login: ';
    var_dump( $app->login( array('username'=>$params['username'],'password'=>$params['password']) ) );

} catch (Exception $ex) {

    echo 'Exception: ',  $e->getMessage(), '\n';

}
Powered by Kunena Forum