Check if user registration field is set to visible or hidden on the registration form In the user registration form, I have set a certain field say surname as hidden i.e. I have unchecked the checkbox saying "Display on user registration form." as shown below:



Now I want to disable the server side validation for this field. When I print the $form array, the surname field is still displayed. However I am not able to find any such value in the $form array which checks if the value is unchecked or not. Is there any way to figure out if the said field is not displayed on the registration form? Hope I am clear enough.
If you look at the code of user_register_form(), you will notice it uses the following code.

  foreach (field_info_instances('user', 'user') as $field_name =&gt; $instance) {
    if (empty($instance['settings']['user_register_form'])) {
      $form[$field_name]['#access'] = FALSE;
    }
  }


If you are implementing hook_form_alter() (or other similar hooks), it's quite easier to look at the #access property. If you need that in other functions, you can use code similar to the following one.

  foreach (field_info_instances('user', 'user') as $field_name =&gt; $instance) {
    if (empty($instance['settings']['user_register_form'])) {
      // $field_name is not supposed to be added to the account registration form.
    }
  }


Clearly, checking for the #access property in a hook_form_alter() implementation is the safer method, since it consider the field can be made accessible from third-party modules (or third-party modules can hide a field that should be visible).
The other method is more for getting a specific field setting.