Removing required attribute on user entity fields not working I have added fields to user entity and make them required and show on registration page. So the user signing up have to fill all the fields. On the admin side these all fields are coming but i don't want to make them required when admin is creating any user. I thought it will be solved if i hook_form_alter  the user registration form and remove the #required attribute. I did this for admin and dpm($form). I set #required =&gt; 0 also unset #required but it keep on showing error of required field. I uncheck the required checkbox in field settings from admin panel and it does not show validation errors on both Admin and Frontend. 

What i want is when admin create a user he just enter username and password and leave the rest of custom fields blank and it should register the user. But on the frontend users have to fill the whole form.

Below is the code:

    // If this is admin creating user
     foreach($form as $key =&gt; $value){
                if(strpos($key, 'field_') !== false){
                    $value['und']['#required'] = 0;
                    unset($value['und']['#required']); // This isn't working either
                }
            }
    // Endif


Updated Full Code:

/**
 * Implements hook_form_alter()
 */
function paypal_signup_form_alter(&amp;$form, &amp;$form_state, $form_id) { 
  if($form_id == 'user_register_form'){
      global $user;
      if(!in_array('administrator', array_values($user-&gt;roles))){
        //Submit handler for redirecting user to Paypal.
        $form['#submit'][] = '_paypal_signup_redirect_paypal';
    } else {
        // Remove validation when admin is creating user.
        foreach (element_children($form) as $key) {
            if (strpos($key, 'field_') !== FALSE) {
              $form[$key][LANGUAGE_NONE][0]['#required'] = FALSE;
              $form[$key][LANGUAGE_NONE]['#required'] = FALSE;
            }
         }
        dpm($form);
    } 
  }
}
Drupal has element_children() to help you safely loop over render arrays. Looping over such arrays manually will inevitably causes problems. Your code should look more like this:

foreach (element_children($form) as $key) {
  if (strpos($key, 'field_') !== FALSE) {
    $form[$key][LANGUAGE_NONE]['#required'] = FALSE;
  }
}


Incidentally, your current code doesn't work because you're modifying a variable that has only ben declared within that function's private scope.