尝试这个,
假设您的提交页面不是 joomla 的一部分,即在 joomla 框架之外。
步骤1:
Include Joomla Frame work
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' );
$mainframe = JFactory::getApplication('site');
$mainframe->initialise();
$db = JFactory::getDBO();
第2步:
Collect your Form fields data.
//Something like $user_email ,$password etc.
第 3 步:检查用户名是否已存在于数据库中。
$sql ="SELECT * FROM #__users WHERE username ='$username'";
$db->setQuery($sql);
$db->query();
if($db->getNumRows()>0){
$mainframe->redirect("url","error msg","error");
}
else{
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password, $salt);
$password = $crypt.':'.$salt;
//Data to login table
$sql= "INSERT INTO #__users(username,email,lastvisitDate,registerDate,block,sendEmail,password,name,params,) values('$user_email','$user_email','$now','$now',0,0,'$password','$full_name','{}')";
$db->setQuery($sql);
$db->query();
$last_inserted_id = $db->insertid();
//User group tabe normally group id for registered user is 2 other wise you have to check that too
$sql= "INSERT INTO #__user_usergroup_map(user_id,group_id) values('$last_inserted_id',2)";
$db->setQuery($sql);
$db->query();
//Finally send a mail to user if required.
JUtility::sendMail(mailfrom, fromname, $user_email, $emailSubject, $email_body,true);
}
希望有意义..