By drupaloSa on
I've a cck node type called "eklenti". This node type is associated with a vocabulary but i don't want to display taxonomy selection on the node creation form (instead i use a modified NAT module which creates a term with the same name as the node and assigns it to the node automatically when the node is saved).
I searhed in the forums and thought that this could be done with the form alter. I wrote the following as a custom module and enabled it. Now i see the drupal message when i go to create an "eklenti" node type, but the taxonomy selection is still there. I don't know what i did wrong. I'd appreciate any help to make this work.
<?php
/**
* Implementation of hook_form_alter().
*
* The function is named modulename_form_alter.
*/
function hidetax_form_alter(&$form, &$form_state, $form_id) {
// Only alter node forms
if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && !isset($form_state['node_preview'])) {
$node = $form['#node'];
if($node->type == 'eklenti') {
$form['taxonomy']['2']['#type'] = 'hidden';
drupal_set_message("Altering '$form_id'");
}
}
}
?>
Comments
perhaps looking at
perhaps looking at http://drupal.org/project/taxonomy_hide might help.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
not useful
Thanks, but after looking at the taxonomy_hide code i couldn't find a solution for my problem. Taxonomy hide uses the following code to hide terms on node display:
The terms of specified vocabularies are unset so they are not displayed on the node view. However, i need to remove the term selection from the node creation and editing pages.
same here
+1 need this too...
+1 want to hard code CCK field in D7
+1 I'm new to Drupal module development, and I'm seeing the same issue. I can easily hard code the title. Now I want to do the same for a CCK field in Drupal 7.
I'm using print_r($form); to get an idea of what's available, and here's a snippet.
unset taxonomy #theme
Pertains to D6:
Not sure if anyone is still looking for this, but altering the taxonomy #type alone won't get the form element to be hidden. Unset the taxonomy theme function and you'll be able to hide it.
Keep in mind that passing at as a hidden type isn't foolproof. You might be better off using #type='value'. Hope someone finds this helpful!
If the taxonomy is set to
If the taxonomy is set to required in the vocab edit page, you will also need to change that to be not required:
-----
BeFused - Drupal tutorials
<?php /** * Implementation