I have a node type 'review' which is attached to two vocabularies and are appearing in a fieldset named VOCABULARIES in the node form.

But what i don't want them to be in a fieldset, so i created this module. But am not having any success with it. I increased the module weight after reading the forums but still nothing. Can any one tell me what i am doing wrong here..?

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'review_node_form') {
      $form['taxonomy'][2]['#collapsible'] = FALSE;
      $form['taxonomy'][3]['#collapsible'] = FALSE;
    }
  }

Comments

jaypan’s picture

I haven't looked at the specifics of the taxonomy fieldset, but in the past when wanting to remove fieldsets, I've done this.

First, lets assume that the original form definition looks like this:

$form['fieldset'] = array
(
  '#type' => 'fieldset',
  '#title' => t('Fieldest'),
);

$form['fieldset']['item'] = array
(
  '#type' => 'textfield',
  '#title' => t('Item'),
);

Then in hook_form_alter, I would do this:

$form['item'] = $form['fieldset']['item'];
unset($form['fieldset']);

This assigns the part you want to keep to a new form element, then clears out the entire last element. The important part is that you keep the name of the element exactly the same, as submit functions will be looking for that specific name. You can see that I named the new element $form['item'], as the old element was $form['fieldset']['item'].

Note: There are a few circumstances where this won't work because the original form submission function is set to work with the tree, so taking out one element screws things up. This is quite a rare case though.

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

khanz’s picture

thanks for the detailed reply.. i used above solution somewhat like this...

function mymodule_form_alter(&$form, $form_state, $form_id) {
      $form['taxonomy'] = $form['fieldset']['taxonomy'];
      unset($form['fieldset']);
    }

but it removes the taxonomy field completely. i guess am not able to find correct element name, so how can i find the exact name??

------------
Volvo, Video, Velcro. (I came, I saw, I stuck around.)

jaypan’s picture

Ya, mine was just an example.

To find the element, do this:

function mymodule_form_alter(&$form, &$form_state, $form_id)
{
  form_set_error('<pre>' .print_r($form, true) . '</pre>');
}

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

ckidow’s picture

My version:

function hook_form_alter(&$form, &$form_state, $form_id) {
  if(strrpos($form_id, '_node_form')) {
    //disabling taxonomy fieldset "vocabulary" if there are more than two vocabularies to choose
    unset($form['taxonomy']['#type'],$form['taxonomy']['#title'],$form['taxonomy']['#collapsible'],$form['taxonomy']['#collapsed']);
  }
}

MfG

CKIDOW

goron’s picture

If anyone is looking for a solution to this, I haven't tried the ones above, but here is a simple one that I found which works. Implement a hook_form_alter function as below.

Note that the important line is the one inside the if statement. The rest is implementation-specific.

/**
 * Implementation of hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'mobileapp_node_form') {
    // Remove 'Vocabularies' fieldset.
    $form['taxonomy']['#type'] = 'markup';
  }
}

source: http://drupalbin.com/13098

lelizondo’s picture

This is terrific. Thanks.

Luis

bala.d’s picture

Dude,

Its great and thanks for the same...

lelizondo’s picture

This has been integrated into Node Form Settings 6.x-2.x

Luis

goldhat’s picture

Using the dsm() function provide by the Development (devel) module (http://drupal.org/project/devel) is something I would recommend to anybody looking to analyze and make changes like this one to a form. It could save you hours of trying to understand the complex nested array. It creates a collapsible readout that makes it easy to identify and drill down to nested array elements:


//print out form array using devel module
dsm($form);

goron’s picture

Thanks for the tip. It definitely is tedious trying to understand those arrays. One question: Where would you place this code in a situation like this? Just in page.tpl.php?

Thanks

goldhat’s picture

Usually this would be inside a call to hook_form_alter (http://api.drupal.org/api/function/hook_form_alter) which is in a custom module. However it is possible to get control of a form through the theme layer in template.php but it requires a couple of extra steps - see http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6 for an example.