Forums

Update field after primary key set in second table

coffeej 24 Nov, 2009
My project is moving along nicely... Chrono tools are working well... thanks.

I have a Registration page setup using Chronoforms and Joomla Reg. plugin. The Reg. page sends basic data to jos_users, then sends additional data to 2 other tables - along with cf_user_id. This all works great and populates the database tables as expected.

One issue. Here's what I'm shooting for...
1. Submit Joomla Registration... data inserts into jos_users... other field data proceeds to jos_table2 and jos_table3.
2. Data is inserted into jos_table2 - primary key is generated.
3. Data is inserted into jos_table3. - primary key is generated.
4. At this point, I would like to automatically go back to jos_table2 and put the primary key from jos_table3 into an empty field. Can I do this with Chrono tools? If not, any suggestions for php/Joomla db code that might assist? I'm doing this to quickly take care of some associated records the first time through. Am I living in dream land?

Thanks in advance!
GreyHead 24 Nov, 2009
Hi coffeej,

You don't necessarily need the primary keys. If you are doing this on registration then I'd use the user_id as the key field in the other two tables (you can access this from the Joomla User object once the registration step is complete). Let the other two tables autogenerate a record id but then add the user_id as an extra column.

Then in the future you can tie the records together from the user_id.

Bob

PS If this wasn't a registration form then I'd probably generate a random string to use as a record key for all three tables (again regardless of the autogenerated record id).
coffeej 24 Nov, 2009
I appreciate the quick reply Bob. I think I'm preparing for some future needs that may require joins. As I searched about, it looks like ChronoConnectivity won't allow for that very easily in its current version. Your suggestion about using user_id (and perhaps a 2nd field) will work for now for data input and individual record editing.

If I send users back to the membership form (or a very similar copy of it) to edit their settings (from multiple tables), do I use the Profile Plugin and Joomla Registration at the same time. Or, do I turn off the Joomla Registration plugin and send updated values (like 'name')straight to jos_users? If the password is sent, will it be hashed either way?

Thanks Again,

coffeej
GreyHead 24 Nov, 2009
Hi coffeej,

The Joomla Regstration Plugin is only good for first registrations, not for updating records.

For updating use the Profile Plugin, or a custom form if you want to pull the data from several records.

To update the tables you can connect one form to several tables, provided that the appropriate primary key(s) are in the data and the input names match column names the data will be saved correctly. (Note: This may mean that you need different primary key names for different tables.) Or you can custom code the saves.

Changed passwords won't be hashed, but I think there is a Joomla function that you can call to do that in the OnSubmit Before box.

Bob
nml375 24 Nov, 2009
Hi,
Regarding paswords and hashing; If you use the JUser class to manipulate user records, it'll hash the passwords properly upon invoking the store() method.
Easiest way to get started would probably be to use the JFactory::getUser() method with the user's ID.
Then just bind() and store() the object.

/Fredrik
This topic is locked and no more replies can be posted.