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?
Just thinking out loud here, but probably what you could do is do a hook_form_alter and add a validation handler. Inside that validation handler, you could set the $user object to inactive/blocked.
See: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html...
On Sat, Nov 21, 2009 at 5:19 PM, chocba chocba@gmail.com 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? -- View this message in context: http://old.nabble.com/Create-User-Account-In-A-Blocked-State-tp26460928p2646... Sent from the Drupal - Support mailing list archive at Nabble.com.
-- [ Drupal support list | http://lists.drupal.org/ ]
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?
Thanks Jamie. The snippet works.
Jamie Holly wrote:
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?
-- [ Drupal support list | http://lists.drupal.org/ ]