I am trying to add another tab to the form while a new node is created using Create Content -> Page. I tried to use hook_form_alter but it adds the element to every other form in the system. Please help.

Comments

jaypan’s picture

You need to use $form_id == [form_name] to only target the node creation form.

Contact me to contract me for D7 -> D10/11 migrations.

nico heulsen’s picture

hook_form_alter is the correct way, but you need to filter out by form_id. To define to form_id, you can simple print out the form_id in the hook_form_alter (use the devel module for this http://www.drupal.org/project/devel). See example below

function modulename_form_alter(&$form, $form_state, $form_id){
  dpm($form_id);
  if (isset($form['type']) && isset($form['#node']) && $form_id == 'page_node_form') {
    //do stuff here
  }
}