1

how can I alter my contact form for adding custom classes
I am using contact form of Drupal 7 core module.

2

Or you can use hook_form_FORM_ID_alter() to get the specific contact form. hook_form_alter() will run for every form on the page.

function MYMODULE_form_contact_site_form_alter(&$form, &$form_state, $form_id) {
  $form['name']['#attributes']['class'] = array('class1', 'class2');

  $form['mail']['#attributes']['class'] = array('class1', 'class2');

  $form['subject']['#attributes']['class'] = array('class1', 'class2');

  $form['message']['#attributes']['class'] = array('class1', 'class2');

  // add class to the overall form
  $form['#attributes']['class'] = array('class1');
}

If you don't know how to use custom modules, you'd have to research that first. Dropping this function in and replacing MYMODULE with your module name will make this work.

| improve this answer | |
  • yes this is also the great option. +1 – Amrita Jun 8 '14 at 18:23
1

It can been done by $form_id

 function MYMODULE_form_alter( &$form, &$form_state, $form_id ) {
        if( $form_id == 'contact_site_form' ){
    //PUT YOUR STYLING HERE
    }
}
| improve this answer | |

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.