1

I would like to remove div element on webform textfield. Instead of :

<div class="form-item webform-component webform-component-textfield" id="webform-component-vous-etes--nom">
  <input type="text" id="edit-submitted-vous-etes-nom" name="submitted[vous_etes][nom]" value="" size="60" maxlength="128" class="form-text">
</div>

I would like to have this :

<input type="text" id="edit-submitted-vous-etes-nom" name="submitted[vous_etes][nom]" value="" size="60" maxlength="128" class="form-text">

2 Answers 2

1

You would do this by overriding theme_form_element() in your theme, eg, something along the lines of:

function YOURTHEME_form_element($variables) {

  $element=&$variables['element'];

  if ( /* this is a webform textfield */ ) {

    // create the html without the div wrapper

  } else {

    // do it the standard way

  }

  return /* the html */;

}

A look into includes/form.inc will show you the full theme_form_element() code that you could copy into your function above where necessary.

4
  • Can we custumise the output of the form tag ? : <form id="contact_form" action="" ..."
    – Mamadou
    Commented Apr 7, 2014 at 17:56
  • most definitely, see theme_form() in includes/form.inc and override it similarly as YOURTHEME_form() in your theme's template.php file
    – Jimajamma
    Commented Apr 7, 2014 at 17:59
  • If you're trying to target only one element and have all others flow as normal, return your html for the element you want and have all others hit return theme_form_element($variables); Commented Feb 28, 2015 at 17:44
  • I try this but when there is textarea field it yet return it with div wrapper
    – Yuseferi
    Commented Sep 24, 2015 at 6:15
1
function YOURTHEME_form_element($variables) {
  $element = &$variables['element'];
  if ( isset($element['#remove-div-wrap']) && $element['#remove-div-wrap'] === true ) {
    return preg_replace('/<div[^>]*>|<\/div>/is', '', theme_form_element($variables));
  } else {
    return theme_form_element($variables);
  }
}

Use hook_form_alter() to specify the affected fields:

function YOURTHEME_form_FORMID_alter(&$form, &$form_state, $form_id) {
  $form['mail']['#remove-div-wrap'] = true;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.