Develop Joomla registration using RSForm!

Thursday, 30 August 2012
In many situations, we may need to have Joomla registration function with some specific data fields. But the fields in Joomla core registration is always having those default fields and do not match the requirements sometimes. So we may consider to choose RSForm to develop a better solution. First of all, we can create a new form which is something similar to the normal registration of Joomla using RSForm, with data fields like name, username, email, password and a submit button. After that the generated form layout code should be something like this:
{global:formtitle}
{error}
{username:caption} {username:body}
{username:validation}
{username:description}
{name:caption} {name:body}
{name:validation}
{name:description}
{email:caption} {email:body}
{email:validation}
{email:description}
{password:caption} {password:body}
{password:validation}
{password:description}
{Submit:caption} {Submit:body}
{Submit:validation}
{Submit:description}
Now we need to transfer the data into Joomla so that Joomla user database could have the registering data from the form we created. In the script tab of the created form in RSForm, inside the text area of "Script called after form has been processed", using the codes below:
// load language
$lang = JFactory::getLanguage();
$lang->load('com_user', JPATH_SITE);
 
// get config for com_users
$usersConfig = &JComponentHelper::getParams( 'com_users' );
 
// get the ACL
$acl =& JFactory::getACL();
  
// "generate" a new JUser Object
// it's important to set the "0" otherwise your admin user information will be loaded
$user = JFactory::getUser(0);
  
$data = array(); // array for all user settings
  
// get the default usertype
$usertype = 'Registered';
  
// set up the "main" user information
  
$data['name'] = $_POST['form']['name']; // add first- and lastname
$data['username'] = $_POST['form']['username']; // add username
$data['email'] = $_POST['form']['email']; // add email
$data['gid'] = $acl->get_group_id( '', $usertype, 'ARO' );  // generate the gid from the usertype
  
/* no need to add the usertype, it will be generated automaticaly from the gid */
  
$data['password'] = $_POST['form']['password']; // set the password
$data['password2'] = $_POST['form']['password']; // confirm the password
$data['sendEmail'] = 1; // should the user receive system mails?
  
$data['block'] = 0; // don't block the user
 
// If user activation is turned on, we need to set the activation information
$useractivation = $usersConfig->get( 'useractivation' );
if ($useractivation == '1')
{
    jimport('joomla.user.helper');
    $user->set('activation', JUtility::getHash( JUserHelper::genRandomPassword()) );
    $data['block'] = 1;
}
 
if (!$user->bind($data)) { // now bind the data to the JUser Object, if it not works....
    JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
    return false; // if you're in a method/function return false
}
  
if (!$user->save()) { // if the user is NOT saved...
    JError::raiseWarning('', JText::_( $user->getError())); // ...raise an Warning
    return false; // if you're in a method/function return false
}
 
// Send emails
require_once(JPATH_SITE.DS.'components'.DS.'com_user'.DS.'controller.php');
UserController::_sendMail($user, $data['password']);
Now the form is able to be used as registration of Joomla. You can also add an auto login function by adding the code below:
//auto login
$usersipass['username'] = $_POST['form']['name'];
$usersipass['password'] = $_POST['form']['password']; 
$mainframe->login($usersipass);
$mainframe->redirect( 'index.php' );

Comments

Ahaa, its good conversation regarding this paragraph here at this blog,
I have read all that.

I really like your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I'm looking to design my own blog and would like to find out where u got this from. kudos

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Target Image

Recently posted

  • We are going to lunch a new extension of Chrome here for web proxy that works with Twitter, Facebook and Youtube. 2 years 3 months ago
  • Pluton - Free Single Page Bootstrap Html Template http://t.co/ADhr6O0qGs 2 years 3 months ago
  • Thanks Michael 2 years 3 months ago

Get a quote now

Don't deply your growing business. Contact us today to find out what we can help.

If you’re considering outsourcing your project development, need to update an existing website or simply need some good advice from someone who listens, get in touch with JoomlaCreator today.