Categories

Featured templates

Drupal 7.x. How to add/change contact form fields placeholders

Lana Greene April 3, 2015
Rating: 5.0/5. From 1 vote.
Please wait...

This tutorial shows how to change or add contact form fields placeholders in Drupal 7.x.

Drupal 7.x. How to add/change contact form fields placeholders

In order to change contact form fields placeholders, you should perform the following:

  1. Find sites/all/themes/themeXXX/template.php file on the server via ftp or hosting cpanel file manager.

  2. Open the file with Sublime Text2 or later, Notepad++, Dreamweaver CS5.5+(Code mode only) or any php-editor.

  3. Check if you have the following code at the bottom of the file:

     
      function theme941_form_contact_site_form_alter( &$form, &$form_state, $form_id ) { 
      $form['name']['#attributes']['placeholder'] = t( "Name123:" ); 
      $form['name']['#title_display'] = 'invisible'; 
       
      $form['mail']['#attributes']['placeholder'] = t( "E-mail:" ); 
      $form['mail']['#title_display'] = 'invisible'; 
       
      $form['subject']['#attributes']['placeholder'] = t( "Subject:" ); 
      $form['subject']['#title_display'] = 'invisible'; 
       
      $form['message']['#attributes']['placeholder'] = t( "Message text:" ); 
      $form['message']['#title_display'] = 'invisible'; 
       
      unset ($form['copy']); 
      }  
    
  4. Change placeholders values:

    Drupal.-How-to-change-contact-form-fields-placeholders

  5. Save changes.

  6. Re-upload the edited file to the server.

  7. If you did not locate the code in the file, you will need to add this code to the bottom of the template.php file:

      
    function themeName_form_alter(&$form, &$form_state, $form_id) {
      if ($form_id == 'contact_site_form') {
      // Changing placeholder attributes values
      $form['name']['#attributes']['placeholder'] = t( 'Your name' );
      $form['mail']['#attributes']['placeholder'] = t( 'Your e-mail' );
      $form['subject']['#attributes']['placeholder'] = t( 'Your subject' );
      $form['message']['#attributes']['placeholder'] = t( 'Your message' );
      }
      }
    
  8. Save changes.

  9. Re-upload the edited file to the server.

Feel free to check the detailed video tutorial below:

Drupal 7.x. How to add/change contact form fields placeholders

Drupal Templates
This entry was posted in Drupal Tutorials and tagged contact, drupal, field, placeholder. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket