Forums

[SOLVED] Update table to assign user to different user group

dmontpe 18 Jul, 2011
I'm trying to use a form to assign a user to a different user group, so besides saving to its own corresponding table, it has to save data to the #__user_usergroup_map table.

I read the tutorial for CFv3 and it said you could choose multiple tables in the same db connection, but in CFv4 that's not possible, so my guess is I have to add 2 db saves so I did just that.

The db save for the form's table works fine but the db save for the user groups table doesn't get updated.

I turned on the debugging option of Joomla and got an interesting result: the query created by the db save action was "SET user_id WHERE group_id = '9'", which is clearly the opposite of what it should be and the reason why no record is found. Then I checked the database in PHPMyAdmin and I found that both fields are marked as one single primary key. (they appear like grouped together, hope that makes sense)

Using a query in PHPMyAdmin does work, just in case. So my guess is the problem comes when CF tries to identify the primary key for the record.

So, the question is, obviously, how could I make the db save work here?


David
dmontpe 22 Jul, 2011
Well, just to update on this. I don't think there's a way to make the db save action work with the user groups table so I went ahead and inserted a custom code to update the jos_user_usergroup_map table directly.

I will mark this as solved since, well, it is solved.
GreyHead 23 Jul, 2011
Hi David,

I can confirm that the ChronoForms DB Save action can't handle this kid of table*.

There probably is a Joomla! User method that you can call to set a user/group membership.

Bob

* There needs to be a single record to be updated and the record must have an integer primary key set.
dmontpe 25 Jul, 2011
Hi, Bob.

Yes, there should be one (not in the Joomla docs, though, since they're still for to 1.5 and user groups have changed in 1.6), but I used getDBO instead because the users won't change their group themselves but I will be the one doing it when approving their request, so they won't be logged in when the change is supposed to happen.

Anyway, if somebody else needs this to be done and want to try the getUser method, I think they should post a question in the Joomla forums.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger