7

I've made a custom Drupal module. Inside which I've created a block and a form. How can I make the form appear in the block content? Cheers.

Block Code:

function module_block($op = 'list', $delta = 0, $edit = array()) { 
  $block = array();

  if ($op == "list") {
    // Test
    $block[0]["info"] = t('Block');
  }
  else if ($op == 'view') {
    $block['content'] = module_function();
  }

  return $block;

}


// End module_block

Form Code:

function module_my_form($form_state) {

  $form['email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#required' => TRUE,
  );

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

Cheers again for any help.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Doyle
  • 295
  • 2
  • 8

1 Answers1

14

For anyone looking, change:

$block['content'] = module_function();

to

$block['content'] = drupal_get_form('module_my_form');

Cheers

leymannx
  • 5,138
  • 5
  • 45
  • 48
Doyle
  • 295
  • 2
  • 8