How would I go about adding html/css into this module e.g. to place the different form items into a table, so i could have a column with one field entry the next column with another entry, and then rows below with other entry fields. I noticed when i put an image into the module it appears on every page on the website too?

 function form_example_menu(){
   $items = array();
   $items['form_example'] = array(
   'title' => 'My example form',
   'type' => MENU_NORMAL_ITEM,
   'access arguments' => array('access form_example'),
   'page callback' => 'drupal_get_form',
   'page arguments' => array ('form_example_form'),
 return $items;

function form_example_form($form, &$form_state){

    $form['mytextfield'] = array (
    '#type' => 'textfield',
    '#title' => t('My text field'),
    '#size' => 60,
    '#maxlength' =>128,
    '#required' => TRUE,

 $form['mytext'] = array (
   '#type' => 'textarea',
   '#title' => t('My text area'),
   '#description' => t('enter some text.'),
   '#defauly value' => '',
   '#required' => TRUE,

 $form['submit'] = array(
   '#type' => 'submit',
   '#value' => t('Add an item'),
return $form;

2 Answers 2


You can use #prefix and #suffix to add any amount of html markup to your form and/or any of its fields. Tons of information can be found in the Drupal Form API Reference. I would tend to suggest you stay away from tables and instead investigate css floats and divs, most probably doable without any additional markup, but that's just personal preference.


You can also theme form using hook_theme and using theme function for its theme like:

function form_example_theme($existing, $type, $theme, $path) {
  return array(
      'form_example_form' => array(
          'render element' => 'form',

function theme_form_example_form($variables) {
  $form = $variables['form'];
  $output = '';
  $output.= '<div class="custom-form">            
              ' . drupal_render($form['mytextfield']) . '
             <!--  Add your HTML and render field the same way  -->   
  $output.= drupal_render_children($form);
  return $output;

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.