How to use hook_form_alter to hide a form field for certain users? function custom_form_alter(&amp;$form, &amp;$form_state, $form_id) {

global $user;
$node = node_load(arg(1));
$num  = $node-&gt;field_node_reference['und'][0]['nid'];
$val  = node_load($num);
$event_noderef_uid = $val-&gt;uid;



if($form_id == 'regester_node_form'){

if($user-&gt;uid == $event_noderef_uid){
 $form['field_NAME']['#access'] = FALSE;        
 }


I want to get ($user->uid == $val->uid) to Hide "field_NAME"
You can clean up the code a bit by using hook_form_FORM_ID_alter:

function mymodule_form_regester_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  global $user;
  $node = node_load(arg(1));
  $num  = $node-&gt;field_node_reference['und'][0]['nid'];
  $val  = node_load($num);
  $event_noderef_uid = $val-&gt;uid;

  if($user-&gt;uid == $event_noderef_uid){
    $form['field_NAME']['#access'] = FALSE;        
  }
}


Other than that, if field_NAME exists in the form and the condition is true, access will be set to FALSE. If you are testing this as user 1, you may not be seeing the results you desire as that is the superuser. It would help if you posted the form you are trying to alter and what its structure is for field_NAME. Probably a really good case to write an automated test for as well.