Skip administrator approval upon registration of some user roles

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by pyone on October 26, 2012 at 8:10am

I have all together 4 user roles.
Users of role 1 & 2 will be activated only when administrator approved them after registration.
But users of role 3 & 4 can immediately access the site after registration.

Is there any way to achieve it by existing module ?

I got different user profiles using profile2 module and I'm using drupal 7.15.

Categories: ,

Comments

I've achieved this using this

Posted by reysharks on October 26, 2012 at 9:38am

I've achieved this using this hook:

function mymodule_form_profile2_edit_PROFILETYPE_form_alter(&$form, &$form_state){
$form["account"]["status"]["#default_value"] = FALSE;
}

I've configured the site to simple registration (with email confirmation), but if the profile type is PROFILETYPE then the account is disabled by default.

I've to use the profile registration path module to hook this form alter.

Hope to be usefull

Yes, it does. Thanks you so

Posted by pyone on November 3, 2012 at 8:52pm

Yes, it does.
Thanks you so much for your help.

I know it's an old thread but...

Posted by Noraj on May 7, 2013 at 9:50am

I'm trying to do the same thing on my website; however I'm not using the profile2 module as I don't need it.
Do you have any idea ?

Thanks for your help.

Can be done using rules

Posted by Virang on December 16, 2015 at 7:37am

Hi Naroj,

Create rule react on event "After saving a new user account" and then call action "Block a user". Make sure check your role in conditions which you want to block all users with same role.

Hi Virang, True that rule

Posted by mayuri_02 on December 16, 2015 at 7:55am

Hi Virang,

True that rule working perfectly fine if we have 2 role like role1 and role2 and we want admin approval only for role1 then create rule.

thanks
mayuri

Hi, the method is the same

Posted by reysharks on May 7, 2013 at 10:05am

Hi,

the method is the same but you must hook the registration form submit and check if a role is selected and then modify the "status" value.

Thank you very much!

Posted by Noraj on May 7, 2013 at 10:28am

I will follow your advice, thank you for helping me so fast ! :)

You're welcome ;)

Posted by reysharks on May 7, 2013 at 10:32am

You're welcome ;)

Hi ! Just tried your

Posted by Noraj on May 8, 2013 at 7:14am

Hi !

Just tried your solution. My code is the following one:

<?php
function mymodule_user_register_submit_alter($form, &$form_state) {
//Testing the role selected
if($form_state['autoassignrole_user']['user_roles'] == $roles[7])
{
//Activation of the new account
$form["account"]["status"]["#default_value"] = TRUE;
}
else
{
//The account is disabled
$form["account"]["status"]["#default_value"] = FALSE;
}
}
?>

However, it doesn't work... I think I'm doing something wrong, but I don't know why (I'm quite new to Drupal and php ^^").

Hi there is not an alter for

Posted by reysharks on May 8, 2013 at 7:32am

Hi there is not an alter for submits...you have to alter the register form and add a custom submit (or validate) function where you check the value submitted and change the status.

I think you should read some documentation about forms api and flow.

Try here http://drupal.org/node/1043838 :)

Not working the solution of reysharks for me

Posted by ssoulless on August 12, 2013 at 4:53pm

hi, i just did what reysharks said but it does not work for me....

i have installed the profile2 and profile2 rgpath modules

this is my mymodule.module file

function mymodule_form_profile2_edit_empresa_form_alter(&$form, &$form_state){
$form["account"]["status"]["#default_value"] = FALSE;
}

i use this path to register the profile type "empresa": www.mysite.com/empresa/register
but when i register an user with this path the user is active by default, and i need them disable or blocked by default

any idea?

i could make it work

Posted by ssoulless on August 12, 2013 at 11:37pm

Hi i could solve this problem...

my problem was that i use the loginTobbogan module and thats why my hook didnt work...

but now my question is, how to make it work with loginTobogan?

How to apply hook

Posted by kratos91 on April 12, 2014 at 2:10am

Hi,

I have the same problem but I don't know how to use the hook mentioned before, I hope someone can explain me how to use this hook, I'd be so grateful.

Hi ,in admin under account

Posted by mayuri_02 on December 16, 2015 at 7:57am

Hi ,

in admin under account settings select Visitors option.

just create rule that will Block user once they register .

AltStyle によって変換されたページ (->オリジナル) /