Forums

[SOLVED]Assign user to specific group with Chronoform's form

AlessandroMagnoII 05 Aug, 2013
Hi,
I'm Alessandro, an Italian user. I have one important question.
I have create a form for registering new joomla user. It work correctly but it isn't complete because I can't associate the new user to a specific group.
How can I make it? Wich strument, on the events panel, I should use for do it?

Thanks for your future answer,

Alessandro
GreyHead 06 Aug, 2013
Hi Allessandro,

Please see this FAQ which I have just written.

Bob
AlessandroMagnoII 06 Aug, 2013
Hi,
thank for the answer. I've use your code but don't work. If I change $form with $Registrazione (Registrazione is the name of my form) nothing happen. Why? This is my code:


<?php
if ( !isset($Registrazione->data['azienda']) || !$Registrazione->data['azienda'] ) {
   // Non ci sono gruppi selezionati
   return false;
}

$group_array = array (
'GU' => '9', // GU
'LU' => '10', // LU
'MA' => '11', // MA
'ME' => '12', //  ME
);

$group_id = $group_array[$Registrazione->data['azienda']];
$user_id  = $Registrazione->data['_PLUGINS_']['joomla_registration']['id'];
jimport('joomla.user.helper');
JUserHelper::addUserToGroup($user_id, $group_id);
?> 


azienda is the factory, is the field name of the multychoose box of my form. GU, LU, MA, ME are the name of the groups, the same in the form. 9, 10, 11, 12 are the ID of the corresponding group.

Thank for answer.
AlessandroMagnoII 06 Aug, 2013

Hi Allessandro,

Please see this FAQ which I have just written.

Bob



Hi,
thank for the answer. I've use your code but don't work. If I change $form with $Registrazione (Registrazione is the name of my form) nothing happen. Why? This is my code:


<?php
if ( !isset($Registrazione->data['azienda']) || !$Registrazione->data['azienda'] ) {
   // Non ci sono gruppi selezionati
   return false;
}

$group_array = array (
'GU' => '9', // GU
'LU' => '10', // LU
'MA' => '11', // MA
'ME' => '12', //  ME
);

$group_id = $group_array[$Registrazione->data['azienda']];
$user_id  = $Registrazione->data['_PLUGINS_']['joomla_registration']['id'];
jimport('joomla.user.helper');
JUserHelper::addUserToGroup($user_id, $group_id);
?> 


azienda is the factory, is the field name of the multychoose box of my form. GU, LU, MA, ME are the name of the groups, the same in the form. 9, 10, 11, 12 are the ID of the corresponding group.

Thank for answer.
GreyHead 06 Aug, 2013
Hi Allessandro,

There is nothing in the FAQ that says "change $form with $Registrazione" :-(

Please put it back.

Bob
AlessandroMagnoII 06 Aug, 2013

Hi Allessandro,

There is nothing in the FAQ that says "change $form with $Registrazione" :-(

Please put it back.

Bob



Ahaha:) It's true. I change the $form with $Registrazione because with $form don't work too.

Alessandro
AlessandroMagnoII 06 Aug, 2013
Sorry for my error...work very well! I've find one my error...when I worked with $form I missed " ' " on ['id]...now it work with $form!

Thanks a lot!

Alessandro
GreyHead 06 Aug, 2013
Hi Alessandro,

Well done. Missing quotes are my most common bug and they are hard to find :-(

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