Forums

Joomla Registration form works but???

webjive 12 Aug, 2009
[Plug]ChronoForms is a great form, I wish I had tried it before using some others![/Plug]

I used the example documentation for the Joomla registration form and had it up and running successfully within minutes. Thanks a million for that.

My question is, is there a way to use ChronoForms to create user registrations while logged into Joomla?? The reason for this is we have setup a training site for a client and regional managers need to add the trainees to the system. ChronoForms seemed ideal for that with the Joomla and CB registration plugins.

The hitch I ran into was after typing in the required info and clicking submit, ChronoForms did the same thing as any standard Joomla registration process, it would create the account because I was logged in.

Is there a way to override this behavior so that we can have user logged in and able to create user/trainee accounts so that trainees don't have to do this?
GreyHead 12 Aug, 2009
Hi webjive,

Yes but it will take you some coding.

To add a user to Joomla 'through the back door' you need to edit three tables jos_users, jos_core_acl_aro and jos_core_acl_groups_aro_map - but the last one uses an aro_id that is set in the second one.

If you create the code to write to these three tables then you can add users from anywhere. You'll probably need to use the Joomla Password generator to create passwords but the rest should be straightforward.

Bob
nml375 12 Aug, 2009
Hi webjive & Bob,
Actually, it's somewhat easier than that. Simply create a new JUser object, along with an array holding the various properties (such as username, name, email, password, password2, gid, and perhaps a few other), bind it to the new user object, and save. Just make sure the 'id' property of the object is empty, which tells joomla we're creating a new user rather than editing an existing one.

Rough skeleton code would look like this:
<? $newuser = new JUser(0);
$newparam = array('username' => 'uname', 'password' => 'thesecret', 'password2' => 'thesecret', 'gid' => 17, ....);
if (!$newuser->bind($newparam))
{
  //something went wrong, perhaps inform the user?
} elseif (!$newuser->save())
{
  //somethign went wrong, perhaps inform the user?
}
?>


This way, we don't have to bother with creating salts for the password, setting up proper ARO/ACO's, etc.

/Fredrik
GreyHead 12 Aug, 2009
Hi Fredrik,

Neat!!

I think I did know that somewhere - just that the last site I did I ended up importing a load of users into the db and had that on my mind.

Bob
nml375 12 Aug, 2009
Well, to put it simple...
The last time I attempted to manually edit the #__users table, I ended up restoring "a few" records (roughly 150-200 users) from backups to get #__users, #__core_* tables back in sync.. Figured it was easier to learn the proper way of doing it the next time.. :p

Also a few comments on my previous post;
You'll find the list of properties in the /libraries/joomla/user/user.php file (contains the JUser class). Also, you don't have to worry 'bout the registeredDate, password_clear, and usertype properties, as these are managed by the JUser class upon save. sendEmail specifies whether the user should receive system emails, and params contains a JParameter object matching the kind of usertype (holds details such as language selection, editor, and other misc stuffs).

/Fredrik
webjive 12 Aug, 2009

Hi webjive & Bob,
Actually, it's somewhat easier than that. Simply create a new JUser object, along with an array holding the various properties (such as username, name, email, password, password2, gid, and perhaps a few other), bind it to the new user object, and save. Just make sure the 'id' property of the object is empty, which tells joomla we're creating a new user rather than editing an existing one.

Rough skeleton code would look like this:

<? $newuser = new JUser(0);
$newparam = array('username' => 'uname', 'password' => 'thesecret', 'password2' => 'thesecret', 'gid' => 17, ....);
if (!$newuser->bind($newparam))
{
  //something went wrong, perhaps inform the user?
} elseif (!$newuser->save())
{
  //somethign went wrong, perhaps inform the user?
}
?>


This way, we don't have to bother with creating salts for the password, setting up proper ARO/ACO's, etc.

/Fredrik



Excellent and thanks! Are you suggesting creating (hack) a new class in /libraries/joomla/user/user.php? Not a problem if so. I'll just need to remember that if I perform a core update to the site to re-add this hack.
nml375 12 Aug, 2009
No no,
No need to hack any files, that code (modified to suit your form application) would simply go into the "on submit" (before or after email) box, or possibly serverside validation, in your chronoform.

/Fredrik
webjive 12 Aug, 2009
@Fredrick.. Gotcha.. Simple enough.. I'll give it a whirl and get back with you.
This topic is locked and no more replies can be posted.