You are here

function userprotect_user_edit_fields_validate in User protect 7

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

Custom validation function for complex field protections.

1 string reference to 'userprotect_user_edit_fields_validate'
userprotect_form_user_profile_form_alter in ./userprotect.module
Implements hook_form_user_profile_form_alter().

File

./userprotect.module, line 271
Main module file for the userprotect module.

Code

function userprotect_user_edit_fields_validate($form, &$form_state) {
  $account = $form_state['userprotect']['account'];
  $field = $form_state['userprotect']['field'];
  switch ($field) {
    case 'roles':

      // Add values for all role checkboxes that are valid roles for this user.
      foreach ($account->roles as $rid => $role) {

        // Authenticated user isn't a valid checked item.
        if ($rid != DRUPAL_AUTHENTICATED_RID) {
          if (isset($form[$rid])) {
            form_set_value($form[$rid], 1, $form_state);
          }
        }
      }
      break;
  }
}