Hi,
How difficult would it be to hack the registration process so that some of a new user's details are added to another table in addition to the jos_users table?
To make it a bit more complicated, I'd need to choose which table they go in based on one of the registration fields.
Basically, what I'm trying to achieve is a workaround that will allow me to have people register on my Joomla! site (1.5 stable) and at the same time populate the "tokens" table for a survey system that would give them access to the surveys based on their Joomla! username as the token. Also, since there are multiple surveys, grouped by project, there are multiple token tables needing to be populated, and the appropriate tables would be determined by a field at registration that would have them choose the project (using JoomSuite's JUser component for the extended user details).
I would assume, if I have the survey tokens tables in the same database as Joomla!, that I can take advantage of at least some of the API - at least to connect to the database, etc. Could I then just add a routine to a registration related file that checks the input and chooses the table and then does an insert upon submission at the same time as the details are inserted into jos_user?
[edit - hit "post" too soon]
Or would it be better to do the registration and just add a trigger for an additional script that would query the database based on the $user variable that's available, and then do the insertion to the tokens table - making it a little more after the fact, and perhaps easier to manage when I have to change it?
If that would work, what would I need to add to the registration process to trigger the "external" script?
Thanks.
Registration hack question - put user details in a 2nd table?
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
- SineMacula
- Joomla! Intern
- Posts: 77
- Joined: Sun Aug 21, 2005 5:16 am
- Location: San Jose, CA
- Contact:
Registration hack question - put user details in a 2nd table?
Last edited by SineMacula on Tue Jan 29, 2008 6:15 am, edited 1 time in total.
- SineMacula
- Joomla! Intern
- Posts: 77
- Joined: Sun Aug 21, 2005 5:16 am
- Location: San Jose, CA
- Contact:
Re: Registration hack question - put user details in a 2nd table?
Once again, it seems I should learn to trust that I know enough to give it a shot... and with some reading through the developer's wiki, and a lot of trial and error, I figured it out! 
What I don't know is if this is the best way to do it...
I added the "study" options to /components/com_user/views/register/tmpl/default.php
I also created a new table for the extended user info, because I'll need to access it beyond this process, but I don't want to mess with the jos_users table.
Then in /components/com_user/controller.php after line 236
I added this:
And it works!!
So, my next question, and one I won't be able to answer for myself, is whether this is the best way to achieve this? Could the code be "cleaner" and more efficient?
I'm also wondering about keeping this extra code "external" to the controller.php file - can that be done? It would make it easier when I have to alter it, and when upgrading Joomla!

What I don't know is if this is the best way to do it...
I added the "study" options to /components/com_user/views/register/tmpl/default.php
I also created a new table for the extended user info, because I'll need to access it beyond this process, but I don't want to mess with the jos_users table.
Then in /components/com_user/controller.php after line 236
Code: Select all
// Bind the post array to the user object
if (!$user->bind( JRequest::get('post'), 'usertype' )) {
JError::raiseError( 500, $user->getError());
}
Code: Select all
//add the extra data to the extened user table
$userx->id = NULL
$userx->username=JRequest::getVar('username', 'POST');
$userx->study = JRequest::getVar('study', 'POST');
$database =& JFactory::getDBO();
$database->insertObject('jos_participants', $userx, 'id');
//check which study was indicated, and put username and email in the appropriate tokens table
if(JRequest::getVar('study', 'POST') == 'SGS') {
$userx->id= NULL;
$userx->username = JRequest::getVar('username', 'POST');
$userx->email = JRequest::getVar('email', 'POST');
$userx->study = JRequest::getVar('study', 'POST');
$database =& JFactory::getDBO();
$database->insertObject('lime_tokentest', $userx, 'id');
}
if(JRequest::getVar('study', 'POST') == 'SOS') {
$userx->id= NULL;
$userx->username = JRequest::getVar('username', 'POST');
$userx->email = JRequest::getVar('email', 'POST');
$userx->study = JRequest::getVar('study', 'POST');
$database =& JFactory::getDBO();
$database->insertObject('lime_tokentest2', $userx, 'id');
}
if(JRequest::getVar('study', 'POST') == 'SON') {
$userx->id= NULL;
$userx->username = JRequest::getVar('username', 'POST');
$userx->email = JRequest::getVar('email', 'POST');
$userx->study = JRequest::getVar('study', 'POST');
$database =& JFactory::getDBO();
$database->insertObject('lime_tokentest3', $userx, 'id');
}
So, my next question, and one I won't be able to answer for myself, is whether this is the best way to achieve this? Could the code be "cleaner" and more efficient?
I'm also wondering about keeping this extra code "external" to the controller.php file - can that be done? It would make it easier when I have to alter it, and when upgrading Joomla!
- AmyStephen
- Joomla! Guru
- Posts: 579
- Joined: Wed Nov 22, 2006 3:35 pm
- Location: Nebraska
- Contact:
Re: Registration hack question - put user details in a 2nd table?
Kevin Devine has been working in this area and has already created a User Meta plugin that allows us to customize the user parameters. In phase 2 of his project, Kevin is working on expanding this customization to also include tables linked on the userid.
He is trying to pave that path that the core developers made available for this purpose. Extensibility was planned, even without core hacks. You might want to look at his work and see if these directions are helpful.
Hope that helps.
Amy
He is trying to pave that path that the core developers made available for this purpose. Extensibility was planned, even without core hacks. You might want to look at his work and see if these directions are helpful.
Hope that helps.
Amy

~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/
http://OpenSourceCommunity.org/node/1719/
- SineMacula
- Joomla! Intern
- Posts: 77
- Joined: Sun Aug 21, 2005 5:16 am
- Location: San Jose, CA
- Contact:
Re: Registration hack question - put user details in a 2nd table?
Thanks Amy!
That lead me to realize I can also have a "custom" registration page in my template's html directory.
So, next question(s):
How would I make setting the parameter at registration required, like the other fields?
It appears the parameter doesn't get included in the 'POST' function -- or I've not called it correctly. What would I need to do in the file I call from the controller.php to get the params value into another table?
Alternately, I assume there's a way to call for a specific param value? Then I guess I wouldn't need it in a separate table, just get the study value from the param field of the user table. I'll do some digging and some more trial and error. 
Thanks,
Scott
That lead me to realize I can also have a "custom" registration page in my template's html directory.

So, next question(s):
How would I make setting the parameter at registration required, like the other fields?
It appears the parameter doesn't get included in the 'POST' function -- or I've not called it correctly. What would I need to do in the file I call from the controller.php to get the params value into another table?
Code: Select all
$userx->username = JRequest::getVar('username', 'POST');
$userx->study = JRequest::getBar('study', 'POST'); //not sure what to put here (this doesn't work - the param name is 'study')
$database =& JFactory::getDBO();
$database->insertObject('jos_participants', $userx, 'id');

Thanks,
Scott
Last edited by SineMacula on Tue Jan 29, 2008 7:06 pm, edited 1 time in total.
Re: Registration hack question - put user details in a 2nd table
This conversation covers exactly what I was hoping to do with my project, and I only stumbled across it after about three hours of keyword searching.
Any updates on your progress would be huge.
Any updates on your progress would be huge.