0

There are two approaches that have failed:

  1. In the theme, add a theme hook for the node edit form. Then, create a template file for the node edit form. This won't work for my case, because the form is rendered in the template file with drupal_render_children, and therefore the contents of the form are not reachable within the template file--I need to add the divs in between the form elements.

  2. Use hook_form_alter. This won't work for my case, because you have to target a specific form item. The users may, for example, add a new node field after I hand it off to them, and my existing hook_form_alter wouldn't have a way to catch it.

What I want to do is simple; in between every element on the node edit form, insert a <div class="clearfix"></div> to separate them.

Or, I could add the "clearfix" class to the existing div containers around the form elements.

Do we have a solution for either method?

[EDIT] Here is the solution using hook_form_alter():

<?php
/**
 * Implements hook_form_alter()
 */
function mytheme_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match('/node_form$/', $form_id)) {
    $language = $form['language']['#value'];
    foreach ($form_state['field'] as $field => $field_contents) {    
      $form[$field][$language]['#suffix'] = '<div class="clearfix></div>';
    }
  }
}
?>
1

The easiest way is using hook_form_alter for each Field add #suffix => '<div class="clearfix"></div>" to the existing FAPI array for the Field. I would just hard code it per field.

If you need to you could make a for loop and walk through the FIELDs so you dont hardcode the fields by hand ... If you were more crazy you could use an #after_build function too on the $form or set 1 per Field element as needed if you run into problems.

|improve this answer|||||
  • Yes, using hook_form_alter() worked for me. – ouni Oct 2 '13 at 17:10

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.