3

How can I hide field labels from Drupal (without CSS)?

http://s6.hostingkartinok.com/uploads/images/2013/04/b35dca469a03a8827f5f3d0576e6f475.png


function clean_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "user_register_form") {
    $form['account']['name']['#title'] = Null;
    $form['account']['name']['#description'] = Null;
    $form['account']['name']['#attributes'] = array('placeholder' => t('Имя пользователя'));

    $form['account']['mail']['#title'] = Null;
    $form['account']['mail']['#description'] = Null;
    $form['account']['mail']['#attributes'] = array('placeholder' => t('mail'));    
  }
}

I don't know how to write for password and date.

10

Go to "Admin > Content Type > Manage Display" and hide the labels as shown in the screenshot.

screenshot

  • i don't have manage display in my content type – Колюха Коваленко Apr 3 '13 at 8:51
  • "Manage display" does not apply to forms. Of course one could use hook_form_alter(). But I am also looking for a solution that does not require hard-coding of field names. – donquixote Apr 28 '16 at 2:13
1

If you need to hide field labels in a node or nodes of one or more content types, and you want to do it conditionally, you can use template_preprocess_page() like so:

function mytheme_preprocess_page(&$variables) {
    if($variables['node']->type == 'yourNodeType') {
        // hide what you wish here
    }
}
0

just hide the label by going in content type->select the content type->manage display..then under the tag LABEL ,select hidden in tha select list options.

0

If you are using Drupal 6 then the manage display link won't be visible. then you need to manually alter the form using form_id and hook_form_alter by creating your custom module (The following code works in Drupal 7 too..). For Ex.

mymodule_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == 'your_form_id') {
     $form['password_field_name']['#title'] = NULL;
     $form['date_field_name']['#title'] = NULL;
   {
}

you need to first debug $form_id for which you need to alter the fields in your mymodule_form_alter() function and then debug the $form for your specific field names of password_field_name and date_field_name.

Hope this helps.

0

If you are using default user register form then

$form['account']['pass']['#title'] = NULL;

If you have added manually by going into content-type then add this line in alter hook

$form['field_password'][LANGUAGE_NONE][0]['value']['#title'] = NULL; 

['field_password'] will change according to you. EX :
If you have created a field with name Password then it will have 'field_password'
Hope this will help you and other

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.