I have a specific content type in drupal6. I want to implement a hook, which hides the body field of that content type from the add form, but not from the edit form. How can I do that?
Select the element and click the gear icon to open the Properties panel. Go to the Advanced tab. Scroll down and toggle the Hide Field option to “On”.
$form['field_name']['#attributes']['class'][] = 'hidden'; Drupal core will "display: none;" this element from core styles using the 'hidden' css class. Show activity on this post. You don't need to set invisible, it will be hidden by default unless the visible condition is met.
Navigate to the "Manage Fields" Tab. Under Label choose "Hidden" and for Format, "Generic File" Save and create a new node of this content type and the name "file" should no longer be displayed.
In the content type's "display fields" tab, edit the display of the field for e.g. 'full node' to be editable. Create a new node of this content type and save it. Now go and visit this node. You will find that you can edit the field.
You can use hook_form_alter. Which you can programmatically alter the contents of the form api build. This gives you the full $form array of which you can simply unset($form['the_field_you_dont_want']);
.
But the easier way to get rid of the body field is in the edit content type there is a field labelled 'Body field label:' just leave this blank and the body field will be omitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With