Search code examples
formsdrupaldrupal-7placeholder

Adding placeholder text to Drupal 7 user_register_form


So I can get the email and username field to work just fine.

here is the code

if ( TRUE === in_array( $form_id, array('user_register_form'))) {
   $form['account']['name']['#attributes']['placeholder'] = t(' Username ');
   $form['account']['name']['#title_display'] = "invisible"; 
   $form['account']['mail']['#attributes']['placeholder'] = t(' Your Email ');
   $form['account']['mail']['#title_display'] = "invisible"; 

}

This works fine. But it seems the person who set this up is using custom field in the form because the it shows:

name="profile_installer_contractor[field_installer_first_name][und][0][value]"

How can I get these fields to show the placeholder text? I have tried:

 $form['account']['field_installer_first_name'][und][0]['value']['#attributes']['placeholder'] = t(' First Name ');

but that doesn't seem to work. Any help is greatly appreciated.

Thanks, Kevin


Solution

  • nevermind I figured it out on my own.

    $form[profile_installer_contractor]['field_installer_first_name'][und][0]['value']['#attributes']['placeholder'] = t(' First Name ');
    

    this worked