I've created a new node type that is identical to a page called "foo", except there is an extra text field, "bar".
When I want to add a new "foo" form as a user, the label for this field "bar" appears above the input box. I would not like it to be present.
I couldn't find any way to开发者_运维百科 remove it in the admin section, and if that's not the case, I tried writing a simple module:
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == "foo_node_form") {
unset($form['bar']['#title']);
}
}
My intention is that this will remove the input field's label but alas, no joy. Any pointers
Taken from http://drupal.org/node/601646...
Try
function mymodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == "foo_node_form") {
unset($form['bar']['value']['#title']);
}
}
If you're just trying to hide a label, then why not use CSS? Apply a display: none;
on the label. You would use hook_form_alter for a bit more advanced work, such as removing form items entirely or adding custom submit handlers.
精彩评论