You are here

function userprotect_user_edit_fields_validate in User protect 5

Same name and namespace in other branches
  1. 6 userprotect.module \userprotect_user_edit_fields_validate()
  2. 7 userprotect.module \userprotect_user_edit_fields_validate()

Custom validation function for complex field protections.

Parameters

$form The form being validated.:

$account The user account.:

$field The user field to check.:

File

./userprotect.module, line 282

Code

function userprotect_user_edit_fields_validate($form, $account, $field) {
  switch ($field) {
    case 'roles':

      // Authenticated user isn't a valid checked item.
      unset($account->roles[DRUPAL_AUTHENTICATED_RID]);

      // Add values for all role checkboxes that are valid roles for this user.
      foreach ($account->roles as $rid => $role) {
        if (isset($form[$rid])) {
          form_set_value($form[$rid], 1);
        }
      }
      break;
  }
}