1

I've a form in my module (mymodule)...

function mymodule_form()
{
   $form['mytext'] = array(
     '#title' => 'Password',
     '#type' => 'password',
     '#size' => 10,
   );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => 'Cool!',
   );
   $form['cool_submit'] = array(
     '#type' => 'submit',
     '#value' => 'Cool Submit!',
   );
   return $form;
}

I've used the hook_entity_view hook to display this form under all drupal entities that are displayed.

function mymodule_entity_view($entity, $type, $view_mode, $langcode) {
  $entity->content['myadditionalfield'] = mymodule_form();
}

When showing this form, drupal adds a DIV tag to the mytext (password field) by itself. I want to override this and provide my own DIV tags and theme to this form. How do I do it?

Thanks :-)

1s2a3n4j5e6e7v
  • 1,243
  • 3
  • 15
  • 29

1 Answers1

0

I worked further on this question to solve it. And the problem got solved. I changed the above code...

function mymodule_entity_view($entity, $type, $view_mode, $langcode) {
  $element = array(
    'start' => array(
        '#type' => 'button',
        '#name' => 'start', 
        '#button_type' => 'submit',
    ),
    'my_text' => array(
        '#type' => 'textfield',
        '#size' => 30, 
        '#maxlength' => 50,
    ),
    'my_submit' => array(
        '#type' => 'button',
        '#name' => 'Submit Discussion',
        '#button_type' => 'submit',
    ),
  );

  $entity->content['disc_bar'] = $element;
}

And the problem kept creeping up whenever a textfield or a password field was rendered. I checked the type array in systems elements info function (a elements_info hook) and found that textfield and password fields come with a default value for the #theme-wrapper. I tried to override it by this way...

'my_text' => array(
        '#type' => 'textfield',
        '#size' => 30, 
        '#maxlength' => 50,
        '#theme-wrapper' => '',
),

and It worked. Its not generating any additional division tags... :-)

1s2a3n4j5e6e7v
  • 1,243
  • 3
  • 15
  • 29
  • you could have added '#theme' => 'your_textfield_theming_function' and use hook_theme() and theme_your_textfield_theming_function() to override the default theming of textfield/password. (btw, the default theming function does some things and wraps it in a form-element theme). – yoavmatchulsky Jun 21 '11 at 15:41