0

Do you have any solution for this?

I know I can hide labels via template.php but how to add placeholders to some inputs?

0
2

SOLUTION 1:

There is a function through which you can add placeholder to every text field based on its title.

function MYMODULE_auto_placeholders(&$element) {
  if ($element['#type'] == 'textfield') {
    $element['#attributes']['placeholder'] = $element['#title'];
  }
  foreach (element_children($element) as $key) {
    MYMODULE_auto_placeholders($element[$key]);
  }
} 

Now in your form_alter() function just call this function;

MYMODULE_auto_placeholders($form);

SOLUTION 2:

To add placeholder to inputs of individual from you can use hook_form_alter .

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'id_of_form') {
    $form['your_element']['#attributes']['placeholder'] = t('Placeholder text');
  }
}

SOLUTION 3:

There is also a module to add placeholder to form input.

Placaeholder:

This project adds an extra FAPI attribute called '#placeholder' to textfield field elements. Often textfields should have some text in them like "Enter your text here" until the user clicks on (or tabs to) the element in question. At that point, the text should disappear and the user can enter his or her desired input.

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