How to acess node object in hook_form_alter I am trying to access the node object in hook_form_alter(), but it throws the following error:


  Notice: Undefined index: #node in themename_form_alter()


The code I am using is the following.

function themename_form_alter(&amp;$form, $form_state, $form_id)) {
  $node = $form['#node'];
}


Is there any way to access the node object in hook_form_alter()?
Not all the forms contains a reference to a node. It is just some node forms which contain a node object, but hook_form_alter() is called for every form being output from Drupal.

What you need to do is the following:


Check $form['#node'] is set  

if (isset($form['#node'])) {
  // …
}

Use a different hook, such as hook_form_node_form_alter() if you want to alter the node edit form for any content type, or hook_form_$type_node_form_alter() for the node edit form of the $type content type