0

I have been searching in vain for days trying to find the right hook or theme override to basically change a few fields I have defined in a custom registration form.

The default markup generated by Drupal is too verbose and the designer has requested that I not change the CSS -- I need to bend the markup to meet the CSS not the CSS to play nice with Drupal.

I have tried hook_field_widget_form_alter and have managed to wrap the existing markup in div's but I need to remove the default:

function tweakform_field_widget_form_alter(&$element, &$form_state, $context) {
  //$element['#prefix'] = '<dir style="background-color: red">';
  //$element['#suffix'] = '</div>';

}

Can someone please show me how this is done? I don't want to re-write the entire form.tpl.php as I only need to override a few fields markup -- then again it may be handy to override the whole thing. These fields are dynamic and controlled by designer and more may be added later or possibly removed.

Alex

0

If you wish to change markup, do it in your theme template.php using THEME_form_element() just take the function from theme_form_element and modify it for your theme. There are also theme hooks for the form and fieldsets.

3
  • I just figured this out, but I am still getting DIV's for each form element without input, labels' etc...I am guessing this is what theme_form and theme_fieldset would allow me to override??? – Alex.Barylski Jun 21 '13 at 19:40
  • Yes they would allow you to strip tags too. There is also a separate one for textareas. – paul.linney Jun 21 '13 at 19:44
  • No textarea, just textfields and a select for now... – Alex.Barylski Jun 21 '13 at 19:55
0
function tweakform_field_widget_form_alter(&$element, &$form_state, $context) {    
  $element['#theme_wrappers'] = '';    
  $element['#prefix'] => '<div class="red">'; 
  $element['#suffix'] => '</div>';
}
2
  • OK I have almost achieved my goal... I am still getting some DIV's added between <form> xxx-add-more-wrapper What method contains this extra markup generation??? Alex – Alex.Barylski Jun 21 '13 at 20:14
  • form.module adds the extra elements... you can override these in your theme by adding yourtheme_formfield() for each element you want to alter, i.e. yourtheme_form_element(), yourtheme_fieldset(), etc. – adam_bear Jun 21 '13 at 20:53

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.