Save form data to two tables, one creating Joomla user

momentis 12 Mar, 2012
I have a form that brings up information previously submitted by web users. When the information is verified, I would like this form to be able to perform two operations:

1) I would like a new Joomla user created, based off a username and password submitted by the web user and displayed on the form; and,
2) Create a new record in a separate table, containing the information previously submitted AND includes the newly-created Joomla userID from #1 above.

So, for example, a user submits the following information:
Name: Rick Stoffiere
Address: 1399 Lear Industrial Parkway, Avon OH 44011
Username: rstoffiere
Password: 123456

The form would pull up this record, but will also provide and additional field called account_number that will be filled in my my client, and ties this user to their internal account information. When this form is submitted, a new Joomla user would be created and given, for example, userid 107. Next, a record would be created in another table containing the user's name, address, account_number, and userid (Joomla). In this way, the user's information in the table I have created would be tied to their Joomla user account.

Is this possible to perform in one form, as I have detailed?
GreyHead 12 Mar, 2012
Hi Rick,

Yes you can do this. Use a Joomla! Registration action for the Joomla! Registration follwoed by a DB Save for your second table. The Joomle Registration caction puts the new user id into the $form->data array so you can move this to a new entry to match the column name in your table.

Bob
momentis 12 Mar, 2012
Thanks, Bob!! I am going to try this out.
GreyHead 13 Mar, 2012
Hi Rick,

I have a document you can buy here that describes how to do this in CFv3 - the concepts are identical in CFv4 though some of the mathodology had changed a bit.

Bob
momentis 13 Mar, 2012
As usual, thanks! Instead of doing this one-by-one, I just bought the entire document pack from your site. If I don't need some of them now, I will!! Oh, and enjoy the beer! :wink:
momentis 21 Mar, 2012
Bob,

I have this working, but I am a little confused on how to achieve the last part of what I need.

The form I have pulls info from a table of registrations (TableA) submitted by users. When the admins review and confirm the user, the following happens:

1) A new Joomla user is created;
2) A "confirmed" flag is set in a field in TableA;
3) A new table of confirmed users is created (TableB), with all of the information from the original registration contained in TableA; and,
4) An email is sent to the original registrant, informing them of their login credentials.

Once the user is created, how can I move their Joomla userID into a field in their newly-created record in TableB?
GreyHead 21 Mar, 2012
Hi Rick,

From memory when you create a new Joomla! User the User object is updated with the new User ID so you can get it from there to add it to the table. If not you can always re-query the User Object with $new_user =& JFactory::getUser('username') as you presumably have the username already.

Bob
momentis 21 Mar, 2012
Thanks! I am still confused, as this is uncharted territory for me. When you say the User object is updated, to what are you referring? How do I access it in the code?

I am really, really sorry for being so obtuse!!!!!!
GreyHead 21 Mar, 2012
Hi Rick,

Hmmm . . . so how are you doing this part 'A new Joomla user is created;'???

Joomla! will get the user data for you in an 'object' (a bundle of variables and methods). Usually you get this for the current user with $user =& JFactory::getUser(); but you can also get the infor for any user by putting an id or a username inside the brackets.

Bob
momentis 21 Mar, 2012
Bob,

I guess it would help you if I explained myself better!!

I am using the CF Joomla User Registration action in the OnSubmit event for this form. After this action, I have 2 DB Save actions - one to set the "Confirmed" flag in the original CF database tabe and the second which stores this same data (but formatted to all caps) into the second table, TableB. TableB also contains the field "acct_user_id", which I need to be populated with the Joomla userID created in the CF Joomla User Registration action above.

If I am still not being clear, I can PM you login details.

Thanks!!!!!!!
GreyHead 22 Mar, 2012
Hi Rick,

I'm still confused by when the Joomla! User is created. Is it when the new user completes the form; or when the admin reviews an application later? If the latter, does it actually work using the Joomla! Registration plug-in?

Bob
momentis 22 Mar, 2012
Hey Bob! I know I must be driving you INSANE. Sorry!! Here's what happens:

1) A user submits information on the site, via a CF form, and the form saves the data to a table (TableA).
2) Admins at my client use a different CF form to open a record from TableA. This form shows all of the data created above, but also includes fields for username and password (which are automatically generated and filled in, thanks to your help on earlier posts!).
3) The admins fill in one additional field, which is the submitter's client ID (internal to their ERP system).
4) The admin clicks "Submit" and the following happens:
a) A flag is set in TableA, indicating that the submission has been approved.
b) A new Joomla user is created, using the Registration plugin.
c) All of the data displayed on the screen (originally from TableA) is stored in a different table, TableB. This data needs to include the Joomla user ID just created in step 4(b).

The step in 4(c), where the user ID created is stored in the new table, is where I am falling flat. Does that help?
momentis 24 Mar, 2012
Bob,

I have reached the limits of my small knowledge base on this one. I keep trying combinations and I am totally lost!!
momentis 26 Mar, 2012
Bob,

Any idea on this one? I am desperate to resolve this. I have NO problem paying you to get the help I need.

Rick
GreyHead 28 Mar, 2012
Hi Rick,

Sorry, this got lost in my backlog of browser tabs 'to come back to when I have more time'.

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.

Bob
momentis 28 Mar, 2012
Thank you SO much for offering to help out!! Info is on the way!
GreyHead 29 Mar, 2012
Hi Rick,

I think that is working now. I added a Custom Code action to save the new User ID into a new $form->data variable:
<?php
$form->data['acct_user_id'] = $form->data['_PLUGINS_']['joomla_registration']['id'];
?>
The acct_user_id column is then correctly updated in the DB Save.

Bob
momentis 29 Mar, 2012
As usual - you got it working!!! Thank you so, so much!!!!! 😀 😀 😀 😀 😀 😀
momentis 29 Mar, 2012
BTW - Enjoy the beer (or coffee or books or whatever)!!!
This topic is locked and no more replies can be posted.