[support] Create User Account In A Blocked State

Jamie Holly hovercrafter at earthlink.net
Sat Nov 21 23:58:05 UTC 2009


You want hook_user. Something like this:

function mymodule_user($op, &$edit, &$account, $category = NULL) {
    //Check for administer users access and have them bypass this if 
necessary
    if ($op=='insert' && !user_access('administer users')){
       if ($edit['my_field_name']!={whatever that should be}){
          $account->status=0;
          db_query("UPDATE {users} SET status=0 WHERE 
uid=%d",$account->uid);
    }
    unset ($edit['my_field_name']); //Do this so it doesn't save the 
value in $user->data;
}

Not tested, but you should get the gist of what I'm doing there. $edit 
will contain the $form_state['values'] so you can do the checks against 
that. Just be sure to unset it when done. If the check fails update the 
db, setting their status to 0 and also set the $account->status to 0, 
that way they won't get an approval email, but rather one stating that 
their account has to be approved by an admin.

Jamie Holly
http://www.intoxination.net 
http://www.hollyit.net



chocba wrote:
> Hi,
> I would like to  perform  a validation on a profile field dispalyed in user
> registration. If this validation fail, I would like to create the user
> account and set his state to blocked. If success, then the user will remain
> as active. Please hlep me how can I achieve this functionality. Right now,
> I'm performing the validation implementing hook_user in profile module. But
> how do I make the user status as blocked instead of active, if the profile
> field validation fails? 
>   


More information about the support mailing list