1

I wanna customize my registration form on drupal 7. I wanna add placeholders and remove the labels. How can I do that? Thank you

2

This could be easily done my hook_form_alter in your custom module. See example below:

Suppose you have a form with id as 'your_form_id' and are looking at overwriting title and placeholder text for a field named 'yourfield', you can create a custom module and add this code to your custom module. You will need to replace 'yourmodule' with the name of your module. Same with 'your_form_id' and 'yourfield'.

     /**
     * Implements hook_form_alter().
     */
     function yourmodule_form_alter(&$form, $form_state, $form_id) {
       switch($form_id) {
         case 'your_form_id':              
           $form['yourfield']['#title'] = t(''); // Remove title from yourfield.
           $form['yourfield']['#attributes']['placeholder']= t('Your placeholder text'); // Set placeholder text for yourfield.
           break;
       }
     }

The t() method is used for internationalisation.

Let me know how you go...

| improve this answer | |
1

You can use Form Place Holder module... I have used it earlier and works like a charm..

Module creates possibility to quickly add (by UI) placeholders to all textfields in any form on site.

| improve this answer | |

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