0

I'm trying to remove a pesky div from within a multistep form I'm trying to customize with a theme. The problem is it's throwing off my css. I'm unwilling to change all my css rules without first knowing a valid reason for this div's existence.

For all my other themed forms this div, strangely, doesn't appear. The only significant difference is this form is multistep. I'm using code based on the example here. I've posted some of the code below.

function theme_mymodule_add_child_wizard($variables)
{
    $form = $variables['form'];
    $output .= '<div class="_'.$form['fname']['#ui_size'].'">';
$output .= drupal_render($form['fname']);
$output .= '</div>';

    $output .= drupal_render_children($form);
    return $output;
}

function hook_theme()
{
return array
(
    'mymodule_add_child_wizard' => array
    (
        'render element' => 'form'
    ),
);
}

My goal is to convert this:

<form>//My Drupal 7 Form
    <div>//Pesky Div
        <input></input>//Form elements contained by Pesky Div
    </div>
</form>

Into this:

<form>
        <input></input>//Form elements free from Pesky Div
</form>

Just for testing purposes, I tried to change line 3842 in the core form.inc file to forcibly remove the div, but it didn't work that way. I don't actually want to change any of the core file, I'd rather find a way to override it within my module.

#Tried removing the <div> tag seen here. 
return '<form' . drupal_attributes($element['#attributes']) . '><div>' . $element['#children'] . '</div></form>';
Saahir Foux
  • 654
  • 4
  • 12
  • 27

3 Answers3

0

try this :

http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#prefix

you can set elements' text or markup.

Please note the "Also see #suffix ." for suffixing the elements.

Antoine Baqain
  • 392
  • 1
  • 3
0

@SFox, you can override the function theme_form inside your template.php

check the API.

sebby
  • 1
  • 1
0

With my knowledge, I think the mentioned div can not be removed by custom hook or theme. You can check this with this code:

function your_module_form($form, &$form_state) {
    $form['#theme_wrappers'] = array(); // remove both <form> and <div> inside
}

function your_module_form($form, &$form_state) {
    $form['#theme_wrappers'] = array('form'); // we want to render only <form> but <div> inside still there
}
  • Theme wrappers hasn't anything to do with the actual markup, instead it's more to do with Drupal's own theme functions (form and block). So this one's a bit of a red herring – Matt Fletcher Jul 17 '17 at 09:32