Search code examples
htmlcssdrupaldrupal-webform

Drupal - Surround specific webform elements with a div


as the title describes, I am to style a webform and for that i need to surround specific fields in divs in order to give them their CSS properties and I have no idea how I should go about doing that.

I've caught the form with hook_form_alter but no idea what to do after.

Any help?


Solution

  • In your themes template.php file you need to get the forms ID and then you can do something like the following:

    function phptemplate_webform_form_FORM_ID ($form) {
      $form['#prefix'] = '<div class="CLASS NAME">';
      $form['#suffix'] = '</div>';
      return _phptemplate_callback('webform_form_FORM_ID', array('form' => $form));
    }
    

    Replace FORM_ID with your form's ID.

    EDIT

    To add them for specific fields just do (something like) this:

    $form['ELEMENT_NAME']['#prefix'] = '<div class="CLASS NAME">';
    $form['ELEMENT_NAME']['#suffix'] = '</div>';
    

    I've not got time to test it but replace ELEMENT_NAME with the element and that should solve your problem. There's a good page on it here - http://drupal.org/node/79086